UNPKG

2.95 kBJavaScriptView Raw
1Object.defineProperty(exports, '__esModule', { value: true });
2
3var utils = require('@sentry/utils');
4
5var SENTRY_API_VERSION = '7';
6
7/** Returns the prefix to construct Sentry ingestion API endpoints. */
8function getBaseApiEndpoint(dsn) {
9 var protocol = dsn.protocol ? `${dsn.protocol}:` : '';
10 var port = dsn.port ? `:${dsn.port}` : '';
11 return `${protocol}//${dsn.host}${port}${dsn.path ? `/${dsn.path}` : ''}/api/`;
12}
13
14/** Returns the ingest API endpoint for target. */
15function _getIngestEndpoint(dsn) {
16 return `${getBaseApiEndpoint(dsn)}${dsn.projectId}/envelope/`;
17}
18
19/** Returns a URL-encoded string with auth config suitable for a query string. */
20function _encodedAuth(dsn, sdkInfo) {
21 return utils.urlEncode({
22 // We send only the minimum set of required information. See
23 // https://github.com/getsentry/sentry-javascript/issues/2572.
24 sentry_key: dsn.publicKey,
25 sentry_version: SENTRY_API_VERSION,
26 ...(sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }),
27 });
28}
29
30/**
31 * Returns the envelope endpoint URL with auth in the query string.
32 *
33 * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
34 */
35function getEnvelopeEndpointWithUrlEncodedAuth(
36 dsn,
37 // TODO (v8): Remove `tunnelOrOptions` in favor of `options`, and use the substitute code below
38 // options: ClientOptions = {} as ClientOptions,
39 tunnelOrOptions = {} ,
40) {
41 // TODO (v8): Use this code instead
42 // const { tunnel, _metadata = {} } = options;
43 // return tunnel ? tunnel : `${_getIngestEndpoint(dsn)}?${_encodedAuth(dsn, _metadata.sdk)}`;
44
45 var tunnel = typeof tunnelOrOptions === 'string' ? tunnelOrOptions : tunnelOrOptions.tunnel;
46 var sdkInfo =
47 typeof tunnelOrOptions === 'string' || !tunnelOrOptions._metadata ? undefined : tunnelOrOptions._metadata.sdk;
48
49 return tunnel ? tunnel : `${_getIngestEndpoint(dsn)}?${_encodedAuth(dsn, sdkInfo)}`;
50}
51
52/** Returns the url to the report dialog endpoint. */
53function getReportDialogEndpoint(
54 dsnLike,
55 dialogOptions
56
57,
58) {
59 var dsn = utils.makeDsn(dsnLike);
60 var endpoint = `${getBaseApiEndpoint(dsn)}embed/error-page/`;
61
62 let encodedOptions = `dsn=${utils.dsnToString(dsn)}`;
63 for (var key in dialogOptions) {
64 if (key === 'dsn') {
65 continue;
66 }
67
68 if (key === 'user') {
69 var user = dialogOptions.user;
70 if (!user) {
71 continue;
72 }
73 if (user.name) {
74 encodedOptions += `&name=${encodeURIComponent(user.name)}`;
75 }
76 if (user.email) {
77 encodedOptions += `&email=${encodeURIComponent(user.email)}`;
78 }
79 } else {
80 encodedOptions += `&${encodeURIComponent(key)}=${encodeURIComponent(dialogOptions[key] )}`;
81 }
82 }
83
84 return `${endpoint}?${encodedOptions}`;
85}
86
87exports.getEnvelopeEndpointWithUrlEncodedAuth = getEnvelopeEndpointWithUrlEncodedAuth;
88exports.getReportDialogEndpoint = getReportDialogEndpoint;
89//# sourceMappingURL=api.js.map