feat: Complete zCode CLI X with Telegram bot integration

- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation

🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
This commit is contained in:
admin
2026-05-05 09:01:26 +00:00
Unverified
parent 4a7035dd92
commit 875c7f9b91
24688 changed files with 3224957 additions and 221 deletions

View File

@@ -0,0 +1,4 @@
import type { HttpRequestParameters } from './http-transport-types';
import { IExporterTransport } from '../exporter-transport';
export declare function createHttpExporterTransport(parameters: HttpRequestParameters): IExporterTransport;
//# sourceMappingURL=http-exporter-transport.d.ts.map

View File

@@ -0,0 +1,87 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var HttpExporterTransport = /** @class */ (function () {
function HttpExporterTransport(_parameters) {
this._parameters = _parameters;
this._send = null;
this._agent = null;
}
HttpExporterTransport.prototype.send = function (data, timeoutMillis) {
return __awaiter(this, void 0, void 0, function () {
var _a, sendWithHttp, createHttpAgent;
var _this = this;
return __generator(this, function (_b) {
if (this._send == null) {
_a = require('./http-transport-utils'), sendWithHttp = _a.sendWithHttp, createHttpAgent = _a.createHttpAgent;
this._agent = createHttpAgent(this._parameters.url, this._parameters.agentOptions);
this._send = sendWithHttp;
}
return [2 /*return*/, new Promise(function (resolve) {
var _a;
// this will always be defined
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(_a = _this._send) === null || _a === void 0 ? void 0 : _a.call(_this, _this._parameters, _this._agent, data, function (result) {
resolve(result);
}, timeoutMillis);
})];
});
});
};
HttpExporterTransport.prototype.shutdown = function () {
// intentionally left empty, nothing to do.
};
return HttpExporterTransport;
}());
export function createHttpExporterTransport(parameters) {
return new HttpExporterTransport(parameters);
}
//# sourceMappingURL=http-exporter-transport.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../src/transport/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcH;IAIE,+BAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;QAH9C,UAAK,GAAwB,IAAI,CAAC;QAClC,WAAM,GAAoC,IAAI,CAAC;IAEE,CAAC;IAEpD,oCAAI,GAAV,UAAW,IAAgB,EAAE,aAAqB;;;;;gBAChD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;oBAEhB,KAIF,OAAO,CAAC,wBAAwB,CAAC,EAHnC,YAAY,kBAAA,EACZ,eAAe,qBAAA,CAEqB;oBACtC,IAAI,CAAC,MAAM,GAAG,eAAe,CAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,EACpB,IAAI,CAAC,WAAW,CAAC,YAAY,CAC9B,CAAC;oBACF,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;iBAC3B;gBAED,sBAAO,IAAI,OAAO,CAAiB,UAAA,OAAO;;wBACxC,8BAA8B;wBAC9B,oEAAoE;wBACpE,MAAA,KAAI,CAAC,KAAK,+CAAV,KAAI,EACF,KAAI,CAAC,WAAW,EAChB,KAAI,CAAC,MAAO,EACZ,IAAI,EACJ,UAAA,MAAM;4BACJ,OAAO,CAAC,MAAM,CAAC,CAAC;wBAClB,CAAC,EACD,aAAa,CACd,CAAC;oBACJ,CAAC,CAAC,EAAC;;;KACJ;IACD,wCAAQ,GAAR;QACE,2CAA2C;IAC7C,CAAC;IACH,4BAAC;AAAD,CAAC,AAtCD,IAsCC;AAED,MAAM,UAAU,2BAA2B,CACzC,UAAiC;IAEjC,OAAO,IAAI,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HttpRequestParameters,\n sendWithHttp,\n} from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../export-response';\nimport { IExporterTransport } from '../exporter-transport';\n\nclass HttpExporterTransport implements IExporterTransport {\n private _send: sendWithHttp | null = null;\n private _agent: http.Agent | https.Agent | null = null;\n\n constructor(private _parameters: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n if (this._send == null) {\n // Lazy require to ensure that http/https is not required before instrumentations can wrap it.\n const {\n sendWithHttp,\n createHttpAgent,\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n } = require('./http-transport-utils');\n this._agent = createHttpAgent(\n this._parameters.url,\n this._parameters.agentOptions\n );\n this._send = sendWithHttp;\n }\n\n return new Promise<ExportResponse>(resolve => {\n // this will always be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._send?.(\n this._parameters,\n this._agent!,\n data,\n result => {\n resolve(result);\n },\n timeoutMillis\n );\n });\n }\n shutdown() {\n // intentionally left empty, nothing to do.\n }\n}\n\nexport function createHttpExporterTransport(\n parameters: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}

View File

@@ -0,0 +1,12 @@
/// <reference types="node" />
import type * as http from 'http';
import type * as https from 'https';
import { ExportResponse } from '../export-response';
export declare type sendWithHttp = (params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number) => void;
export interface HttpRequestParameters {
url: string;
headers: () => Record<string, string>;
compression: 'gzip' | 'none';
agentOptions: http.AgentOptions | https.AgentOptions;
}
//# sourceMappingURL=http-transport-types.d.ts.map

View File

@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};
//# sourceMappingURL=http-transport-types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../src/transport/http-transport-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { ExportResponse } from '../export-response';\n\nexport type sendWithHttp = (\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n) => void;\n\nexport interface HttpRequestParameters {\n url: string;\n headers: () => Record<string, string>;\n compression: 'gzip' | 'none';\n agentOptions: http.AgentOptions | https.AgentOptions;\n}\n"]}

View File

@@ -0,0 +1,17 @@
/// <reference types="node" />
import * as http from 'http';
import * as https from 'https';
import { HttpRequestParameters } from './http-transport-types';
import { ExportResponse } from '../export-response';
/**
* Sends data using http
* @param params
* @param agent
* @param data
* @param onDone
* @param timeoutMillis
*/
export declare function sendWithHttp(params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
export declare function compressAndSend(req: http.ClientRequest, compression: 'gzip' | 'none', data: Uint8Array, onError: (error: Error) => void): void;
export declare function createHttpAgent(rawUrl: string, agentOptions: http.AgentOptions | https.AgentOptions): http.Agent;
//# sourceMappingURL=http-transport-utils.d.ts.map

View File

@@ -0,0 +1,127 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as http from 'http';
import * as https from 'https';
import * as zlib from 'zlib';
import { Readable } from 'stream';
import { isExportRetryable, parseRetryAfterToMills, } from '../is-export-retryable';
import { OTLPExporterError } from '../types';
/**
* Sends data using http
* @param params
* @param agent
* @param data
* @param onDone
* @param timeoutMillis
*/
export function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
var parsedUrl = new URL(params.url);
var nodeVersion = Number(process.versions.node.split('.')[0]);
var options = {
hostname: parsedUrl.hostname,
port: parsedUrl.port,
path: parsedUrl.pathname,
method: 'POST',
headers: __assign({}, params.headers()),
agent: agent,
};
var request = parsedUrl.protocol === 'http:' ? http.request : https.request;
var req = request(options, function (res) {
var responseData = [];
res.on('data', function (chunk) { return responseData.push(chunk); });
res.on('end', function () {
if (res.statusCode && res.statusCode < 299) {
onDone({
status: 'success',
data: Buffer.concat(responseData),
});
}
else if (res.statusCode && isExportRetryable(res.statusCode)) {
onDone({
status: 'retryable',
retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),
});
}
else {
var error = new OTLPExporterError(res.statusMessage, res.statusCode, Buffer.concat(responseData).toString());
onDone({
status: 'failure',
error: error,
});
}
});
});
req.setTimeout(timeoutMillis, function () {
req.destroy();
onDone({
status: 'failure',
error: new Error('Request Timeout'),
});
});
req.on('error', function (error) {
onDone({
status: 'failure',
error: error,
});
});
var reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';
req.on(reportTimeoutErrorEvent, function () {
onDone({
status: 'failure',
error: new Error('Request timed out'),
});
});
compressAndSend(req, params.compression, data, function (error) {
onDone({
status: 'failure',
error: error,
});
});
}
export function compressAndSend(req, compression, data, onError) {
var dataStream = readableFromUint8Array(data);
if (compression === 'gzip') {
req.setHeader('Content-Encoding', 'gzip');
dataStream = dataStream
.on('error', onError)
.pipe(zlib.createGzip())
.on('error', onError);
}
dataStream.pipe(req).on('error', onError);
}
function readableFromUint8Array(buff) {
var readable = new Readable();
readable.push(buff);
readable.push(null);
return readable;
}
export function createHttpAgent(rawUrl, agentOptions) {
var parsedUrl = new URL(rawUrl);
var Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
return new Agent(agentOptions);
}
//# sourceMappingURL=http-transport-utils.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
import { IExporterTransport } from '../exporter-transport';
export interface SendBeaconParameters {
url: string;
/**
* for instance 'application/x-protobuf'
*/
blobType: string;
}
export declare function createSendBeaconTransport(parameters: SendBeaconParameters): IExporterTransport;
//# sourceMappingURL=send-beacon-transport.d.ts.map

View File

@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { diag } from '@opentelemetry/api';
var SendBeaconTransport = /** @class */ (function () {
function SendBeaconTransport(_params) {
this._params = _params;
}
SendBeaconTransport.prototype.send = function (data) {
var _this = this;
return new Promise(function (resolve) {
if (navigator.sendBeacon(_this._params.url, new Blob([data], { type: _this._params.blobType }))) {
// no way to signal retry, treat everything as success
diag.debug('SendBeacon success');
resolve({
status: 'success',
});
}
else {
resolve({
status: 'failure',
error: new Error('SendBeacon failed'),
});
}
});
};
SendBeaconTransport.prototype.shutdown = function () {
// Intentionally left empty, nothing to do.
};
return SendBeaconTransport;
}());
export function createSendBeaconTransport(parameters) {
return new SendBeaconTransport(parameters);
}
//# sourceMappingURL=send-beacon-transport.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"send-beacon-transport.js","sourceRoot":"","sources":["../../../src/transport/send-beacon-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAU1C;IACE,6BAAoB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IACrD,kCAAI,GAAJ,UAAK,IAAgB;QAArB,iBAoBC;QAnBC,OAAO,IAAI,OAAO,CAAiB,UAAA,OAAO;YACxC,IACE,SAAS,CAAC,UAAU,CAClB,KAAI,CAAC,OAAO,CAAC,GAAG,EAChB,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,KAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAClD,EACD;gBACA,sDAAsD;gBACtD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBACjC,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;iBAClB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,mBAAmB,CAAC;iBACtC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,sCAAQ,GAAR;QACE,2CAA2C;IAC7C,CAAC;IACH,0BAAC;AAAD,CAAC,AA3BD,IA2BC;AAED,MAAM,UAAU,yBAAyB,CACvC,UAAgC;IAEhC,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { IExporterTransport } from '../exporter-transport';\nimport { ExportResponse } from '../export-response';\nimport { diag } from '@opentelemetry/api';\n\nexport interface SendBeaconParameters {\n url: string;\n /**\n * for instance 'application/x-protobuf'\n */\n blobType: string;\n}\n\nclass SendBeaconTransport implements IExporterTransport {\n constructor(private _params: SendBeaconParameters) {}\n send(data: Uint8Array): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n if (\n navigator.sendBeacon(\n this._params.url,\n new Blob([data], { type: this._params.blobType })\n )\n ) {\n // no way to signal retry, treat everything as success\n diag.debug('SendBeacon success');\n resolve({\n status: 'success',\n });\n } else {\n resolve({\n status: 'failure',\n error: new Error('SendBeacon failed'),\n });\n }\n });\n }\n\n shutdown(): void {\n // Intentionally left empty, nothing to do.\n }\n}\n\nexport function createSendBeaconTransport(\n parameters: SendBeaconParameters\n): IExporterTransport {\n return new SendBeaconTransport(parameters);\n}\n"]}

View File

@@ -0,0 +1,11 @@
import { IExporterTransport } from '../exporter-transport';
export interface XhrRequestParameters {
url: string;
headers: () => Record<string, string>;
}
/**
* Creates an exporter transport that uses XHR to send the data
* @param parameters applied to each request made by transport
*/
export declare function createXhrTransport(parameters: XhrRequestParameters): IExporterTransport;
//# sourceMappingURL=xhr-transport.d.ts.map

View File

@@ -0,0 +1,102 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { diag } from '@opentelemetry/api';
import { isExportRetryable, parseRetryAfterToMills, } from '../is-export-retryable';
var XhrTransport = /** @class */ (function () {
function XhrTransport(_parameters) {
this._parameters = _parameters;
}
XhrTransport.prototype.send = function (data, timeoutMillis) {
var _this = this;
return new Promise(function (resolve) {
var xhr = new XMLHttpRequest();
xhr.timeout = timeoutMillis;
xhr.open('POST', _this._parameters.url);
var headers = _this._parameters.headers();
Object.entries(headers).forEach(function (_a) {
var _b = __read(_a, 2), k = _b[0], v = _b[1];
xhr.setRequestHeader(k, v);
});
xhr.ontimeout = function (_) {
resolve({
status: 'failure',
error: new Error('XHR request timed out'),
});
};
xhr.onreadystatechange = function () {
if (xhr.status >= 200 && xhr.status <= 299) {
diag.debug('XHR success');
resolve({
status: 'success',
});
}
else if (xhr.status && isExportRetryable(xhr.status)) {
resolve({
status: 'retryable',
retryInMillis: parseRetryAfterToMills(xhr.getResponseHeader('Retry-After')),
});
}
else if (xhr.status !== 0) {
resolve({
status: 'failure',
error: new Error('XHR request failed with non-retryable status'),
});
}
};
xhr.onabort = function () {
resolve({
status: 'failure',
error: new Error('XHR request aborted'),
});
};
xhr.onerror = function () {
resolve({
status: 'failure',
error: new Error('XHR request errored'),
});
};
xhr.send(data);
});
};
XhrTransport.prototype.shutdown = function () {
// Intentionally left empty, nothing to do.
};
return XhrTransport;
}());
/**
* Creates an exporter transport that uses XHR to send the data
* @param parameters applied to each request made by transport
*/
export function createXhrTransport(parameters) {
return new XhrTransport(parameters);
}
//# sourceMappingURL=xhr-transport.js.map

File diff suppressed because one or more lines are too long