1 | Object.defineProperty(exports, "__esModule", { value: true });
|
2 | var utils_1 = require("@sentry/utils");
|
3 | var SENTRY_API_VERSION = '7';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var API = (function () {
|
10 |
|
11 | function API(dsn, metadata, tunnel) {
|
12 | if (metadata === void 0) { metadata = {}; }
|
13 | this.dsn = dsn;
|
14 | this._dsnObject = new utils_1.Dsn(dsn);
|
15 | this.metadata = metadata;
|
16 | this._tunnel = tunnel;
|
17 | }
|
18 |
|
19 | API.prototype.getDsn = function () {
|
20 | return this._dsnObject;
|
21 | };
|
22 |
|
23 | API.prototype.forceEnvelope = function () {
|
24 | return !!this._tunnel;
|
25 | };
|
26 |
|
27 | API.prototype.getBaseApiEndpoint = function () {
|
28 | var dsn = this.getDsn();
|
29 | var protocol = dsn.protocol ? dsn.protocol + ":" : '';
|
30 | var port = dsn.port ? ":" + dsn.port : '';
|
31 | return protocol + "//" + dsn.host + port + (dsn.path ? "/" + dsn.path : '') + "/api/";
|
32 | };
|
33 |
|
34 | API.prototype.getStoreEndpoint = function () {
|
35 | return this._getIngestEndpoint('store');
|
36 | };
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 | API.prototype.getStoreEndpointWithUrlEncodedAuth = function () {
|
43 | return this.getStoreEndpoint() + "?" + this._encodedAuth();
|
44 | };
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 | API.prototype.getEnvelopeEndpointWithUrlEncodedAuth = function () {
|
51 | if (this.forceEnvelope()) {
|
52 | return this._tunnel;
|
53 | }
|
54 | return this._getEnvelopeEndpoint() + "?" + this._encodedAuth();
|
55 | };
|
56 |
|
57 | API.prototype.getStoreEndpointPath = function () {
|
58 | var dsn = this.getDsn();
|
59 | return (dsn.path ? "/" + dsn.path : '') + "/api/" + dsn.projectId + "/store/";
|
60 | };
|
61 | |
62 |
|
63 |
|
64 |
|
65 | API.prototype.getRequestHeaders = function (clientName, clientVersion) {
|
66 |
|
67 | var dsn = this.getDsn();
|
68 | var header = ["Sentry sentry_version=" + SENTRY_API_VERSION];
|
69 | header.push("sentry_client=" + clientName + "/" + clientVersion);
|
70 | header.push("sentry_key=" + dsn.publicKey);
|
71 | if (dsn.pass) {
|
72 | header.push("sentry_secret=" + dsn.pass);
|
73 | }
|
74 | return {
|
75 | 'Content-Type': 'application/json',
|
76 | 'X-Sentry-Auth': header.join(', '),
|
77 | };
|
78 | };
|
79 |
|
80 | API.prototype.getReportDialogEndpoint = function (dialogOptions) {
|
81 | if (dialogOptions === void 0) { dialogOptions = {}; }
|
82 | var dsn = this.getDsn();
|
83 | var endpoint = this.getBaseApiEndpoint() + "embed/error-page/";
|
84 | var encodedOptions = [];
|
85 | encodedOptions.push("dsn=" + dsn.toString());
|
86 | for (var key in dialogOptions) {
|
87 | if (key === 'dsn') {
|
88 | continue;
|
89 | }
|
90 | if (key === 'user') {
|
91 | if (!dialogOptions.user) {
|
92 | continue;
|
93 | }
|
94 | if (dialogOptions.user.name) {
|
95 | encodedOptions.push("name=" + encodeURIComponent(dialogOptions.user.name));
|
96 | }
|
97 | if (dialogOptions.user.email) {
|
98 | encodedOptions.push("email=" + encodeURIComponent(dialogOptions.user.email));
|
99 | }
|
100 | }
|
101 | else {
|
102 | encodedOptions.push(encodeURIComponent(key) + "=" + encodeURIComponent(dialogOptions[key]));
|
103 | }
|
104 | }
|
105 | if (encodedOptions.length) {
|
106 | return endpoint + "?" + encodedOptions.join('&');
|
107 | }
|
108 | return endpoint;
|
109 | };
|
110 |
|
111 | API.prototype._getEnvelopeEndpoint = function () {
|
112 | return this._getIngestEndpoint('envelope');
|
113 | };
|
114 |
|
115 | API.prototype._getIngestEndpoint = function (target) {
|
116 | if (this._tunnel) {
|
117 | return this._tunnel;
|
118 | }
|
119 | var base = this.getBaseApiEndpoint();
|
120 | var dsn = this.getDsn();
|
121 | return "" + base + dsn.projectId + "/" + target + "/";
|
122 | };
|
123 |
|
124 | API.prototype._encodedAuth = function () {
|
125 | var dsn = this.getDsn();
|
126 | var auth = {
|
127 |
|
128 |
|
129 | sentry_key: dsn.publicKey,
|
130 | sentry_version: SENTRY_API_VERSION,
|
131 | };
|
132 | return utils_1.urlEncode(auth);
|
133 | };
|
134 | return API;
|
135 | }());
|
136 | exports.API = API;
|
137 |
|
\ | No newline at end of file |