Email Sorter Beta

Ich habe soweit automatisiert the Emails sortieren aber ich muss noch schauen was es fur bugs es gibt wenn die app online  ist deswegen wurde ich mit diesen Commit die website veroffentlichen obwohjl es sein konnte  das es noch nicht fertig ist und verkaufs bereit
This commit is contained in:
2026-01-22 19:32:12 +01:00
parent 95349af50b
commit abf761db07
596 changed files with 56405 additions and 51231 deletions

View File

@@ -1,6 +1,6 @@
import { StripeAPIError, StripeAuthenticationError, StripeConnectionError, StripeError, StripePermissionError, StripeRateLimitError, } from './Error.js';
import { emitWarning, normalizeHeaders, removeNullish, stringifyRequestData, } from './utils.js';
import { StripeAPIError, StripeAuthenticationError, StripeConnectionError, StripeError, StripePermissionError, StripeRateLimitError, generateV1Error, generateV2Error, } from './Error.js';
import { HttpClient } from './net/HttpClient.js';
import { emitWarning, jsonStringifyRequestData, normalizeHeaders, queryStringifyRequestData, removeNullish, getAPIMode, getOptionsFromArgs, getDataFromArgs, } from './utils.js';
const MAX_RETRY_AFTER_WAIT = 60;
export class RequestSender {
constructor(stripe, maxBufferedRequestMetric) {
@@ -66,7 +66,7 @@ export class RequestSender {
* parses the JSON and returns it (i.e. passes it to the callback) if there
* is no "error" field. Otherwise constructs/passes an appropriate Error.
*/
_jsonResponseHandler(requestEvent, usage, callback) {
_jsonResponseHandler(requestEvent, apiMode, usage, callback) {
return (res) => {
const headers = res.getHeaders();
const requestId = this._getRequestId(headers);
@@ -98,8 +98,11 @@ export class RequestSender {
else if (statusCode === 429) {
err = new StripeRateLimitError(jsonResponse.error);
}
else if (apiMode === 'v2') {
err = generateV2Error(jsonResponse.error);
}
else {
err = StripeError.generate(jsonResponse.error);
err = generateV1Error(jsonResponse.error);
}
throw err;
}
@@ -171,7 +174,7 @@ export class RequestSender {
// Apply exponential backoff with initialNetworkRetryDelay on the
// number of numRetries so far as inputs. Do not allow the number to exceed
// maxNetworkRetryDelay.
let sleepSeconds = Math.min(initialNetworkRetryDelay * Math.pow(numRetries - 1, 2), maxNetworkRetryDelay);
let sleepSeconds = Math.min(initialNetworkRetryDelay * Math.pow(2, numRetries - 1), maxNetworkRetryDelay);
// Apply some jitter by randomizing the value in the range of
// (sleepSeconds / 2) to (sleepSeconds).
sleepSeconds *= 0.5 * (1 + Math.random());
@@ -190,26 +193,34 @@ export class RequestSender {
? settings.maxNetworkRetries
: this._stripe.getMaxNetworkRetries();
}
_defaultIdempotencyKey(method, settings) {
_defaultIdempotencyKey(method, settings, apiMode) {
// If this is a POST and we allow multiple retries, ensure an idempotency key.
const maxRetries = this._getMaxNetworkRetries(settings);
if (method === 'POST' && maxRetries > 0) {
return `stripe-node-retry-${this._stripe._platformFunctions.uuid4()}`;
const genKey = () => `stripe-node-retry-${this._stripe._platformFunctions.uuid4()}`;
// more verbose than it needs to be, but gives clear separation between V1 and V2 behavior
if (apiMode === 'v2') {
if (method === 'POST' || method === 'DELETE') {
return genKey();
}
}
else if (apiMode === 'v1') {
if (method === 'POST' && maxRetries > 0) {
return genKey();
}
}
return null;
}
_makeHeaders(auth, contentLength, apiVersion, clientUserAgent, method, userSuppliedHeaders, userSuppliedSettings) {
_makeHeaders({ contentType, contentLength, apiVersion, clientUserAgent, method, userSuppliedHeaders, userSuppliedSettings, stripeAccount, stripeContext, apiMode, }) {
const defaultHeaders = {
// Use specified auth token or use default from this stripe instance:
Authorization: auth ? `Bearer ${auth}` : this._stripe.getApiField('auth'),
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': this._getUserAgentString(),
'Content-Type': contentType,
'User-Agent': this._getUserAgentString(apiMode),
'X-Stripe-Client-User-Agent': clientUserAgent,
'X-Stripe-Client-Telemetry': this._getTelemetryHeader(),
'Stripe-Version': apiVersion,
'Stripe-Account': this._stripe.getApiField('stripeAccount'),
'Idempotency-Key': this._defaultIdempotencyKey(method, userSuppliedSettings),
'Stripe-Account': stripeAccount,
'Stripe-Context': stripeContext,
'Idempotency-Key': this._defaultIdempotencyKey(method, userSuppliedSettings, apiMode),
};
// As per https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2:
// A user agent SHOULD send a Content-Length in a request message when
@@ -238,12 +249,12 @@ export class RequestSender {
// If the user supplied, say 'idempotency-key', override instead of appending by ensuring caps are the same.
normalizeHeaders(userSuppliedHeaders));
}
_getUserAgentString() {
_getUserAgentString(apiMode) {
const packageVersion = this._stripe.getConstant('PACKAGE_VERSION');
const appInfo = this._stripe._appInfo
? this._stripe.getAppInfoAsString()
: '';
return `Stripe/v1 NodeBindings/${packageVersion} ${appInfo}`.trim();
return `Stripe/${apiMode} NodeBindings/${packageVersion} ${appInfo}`.trim();
}
_getTelemetryHeader() {
if (this._stripe.getTelemetryEnabled() &&
@@ -271,8 +282,61 @@ export class RequestSender {
}
}
}
_request(method, host, path, data, auth, options = {}, usage = [], callback, requestDataProcessor = null) {
_rawRequest(method, path, params, options) {
const requestPromise = new Promise((resolve, reject) => {
let opts;
try {
const requestMethod = method.toUpperCase();
if (requestMethod !== 'POST' &&
params &&
Object.keys(params).length !== 0) {
throw new Error('rawRequest only supports params on POST requests. Please pass null and add your parameters to path.');
}
const args = [].slice.call([params, options]);
// Pull request data and options (headers, auth) from args.
const dataFromArgs = getDataFromArgs(args);
const data = Object.assign({}, dataFromArgs);
const calculatedOptions = getOptionsFromArgs(args);
const headers = calculatedOptions.headers;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const authenticator = calculatedOptions.authenticator;
opts = {
requestMethod,
requestPath: path,
bodyData: data,
queryData: {},
authenticator,
headers,
host: null,
streaming: false,
settings: {},
usage: ['raw_request'],
};
}
catch (err) {
reject(err);
return;
}
function requestCallback(err, response) {
if (err) {
reject(err);
}
else {
resolve(response);
}
}
const { headers, settings } = opts;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const authenticator = opts.authenticator;
this._request(opts.requestMethod, opts.host, path, opts.bodyData, authenticator, { headers, settings, streaming: opts.streaming }, opts.usage, requestCallback);
});
return requestPromise;
}
_request(method, host, path, data, authenticator, options, usage = [], callback, requestDataProcessor = null) {
var _a;
let requestData;
authenticator = (_a = authenticator !== null && authenticator !== void 0 ? authenticator : this._stripe._authenticator) !== null && _a !== void 0 ? _a : null;
const apiMode = getAPIMode(path);
const retryRequest = (requestFn, apiVersion, headers, requestRetries, retryAfter) => {
return setTimeout(requestFn, this._getSleepTimeInMS(requestRetries, retryAfter), apiVersion, headers, requestRetries + 1);
};
@@ -284,50 +348,68 @@ export class RequestSender {
options.settings.timeout >= 0
? options.settings.timeout
: this._stripe.getApiField('timeout');
const req = this._stripe
.getApiField('httpClient')
.makeRequest(host || this._stripe.getApiField('host'), this._stripe.getApiField('port'), path, method, headers, requestData, this._stripe.getApiField('protocol'), timeout);
const requestStartTime = Date.now();
// @ts-ignore
const requestEvent = removeNullish({
api_version: apiVersion,
account: headers['Stripe-Account'],
idempotency_key: headers['Idempotency-Key'],
method,
path,
request_start_time: requestStartTime,
});
const requestRetries = numRetries || 0;
const maxRetries = this._getMaxNetworkRetries(options.settings || {});
this._stripe._emitter.emit('request', requestEvent);
req
.then((res) => {
if (RequestSender._shouldRetry(res, requestRetries, maxRetries)) {
return retryRequest(makeRequest, apiVersion, headers, requestRetries,
// @ts-ignore
res.getHeaders()['retry-after']);
}
else if (options.streaming && res.getStatusCode() < 400) {
return this._streamingResponseHandler(requestEvent, usage, callback)(res);
}
else {
return this._jsonResponseHandler(requestEvent, usage, callback)(res);
}
})
.catch((error) => {
if (RequestSender._shouldRetry(null, requestRetries, maxRetries, error)) {
return retryRequest(makeRequest, apiVersion, headers, requestRetries, null);
}
else {
const isTimeoutError = error.code && error.code === HttpClient.TIMEOUT_ERROR_CODE;
return callback(new StripeConnectionError({
message: isTimeoutError
? `Request aborted due to timeout being reached (${timeout}ms)`
: RequestSender._generateConnectionErrorMessage(requestRetries),
const request = {
host: host || this._stripe.getApiField('host'),
port: this._stripe.getApiField('port'),
path: path,
method: method,
headers: Object.assign({}, headers),
body: requestData,
protocol: this._stripe.getApiField('protocol'),
};
authenticator(request)
.then(() => {
const req = this._stripe
.getApiField('httpClient')
.makeRequest(request.host, request.port, request.path, request.method, request.headers, request.body, request.protocol, timeout);
const requestStartTime = Date.now();
// @ts-ignore
const requestEvent = removeNullish({
api_version: apiVersion,
account: headers['Stripe-Account'],
idempotency_key: headers['Idempotency-Key'],
method,
path,
request_start_time: requestStartTime,
});
const requestRetries = numRetries || 0;
const maxRetries = this._getMaxNetworkRetries(options.settings || {});
this._stripe._emitter.emit('request', requestEvent);
req
.then((res) => {
if (RequestSender._shouldRetry(res, requestRetries, maxRetries)) {
return retryRequest(makeRequest, apiVersion, headers, requestRetries,
// @ts-ignore
detail: error,
}));
}
res.getHeaders()['retry-after']);
}
else if (options.streaming && res.getStatusCode() < 400) {
return this._streamingResponseHandler(requestEvent, usage, callback)(res);
}
else {
return this._jsonResponseHandler(requestEvent, apiMode, usage, callback)(res);
}
})
.catch((error) => {
if (RequestSender._shouldRetry(null, requestRetries, maxRetries, error)) {
return retryRequest(makeRequest, apiVersion, headers, requestRetries, null);
}
else {
const isTimeoutError = error.code && error.code === HttpClient.TIMEOUT_ERROR_CODE;
return callback(new StripeConnectionError({
message: isTimeoutError
? `Request aborted due to timeout being reached (${timeout}ms)`
: RequestSender._generateConnectionErrorMessage(requestRetries),
// @ts-ignore
detail: error,
}));
}
});
})
.catch((e) => {
throw new StripeError({
message: 'Unable to authenticate the request',
exception: e,
});
});
};
const prepareAndMakeRequest = (error, data) => {
@@ -336,9 +418,21 @@ export class RequestSender {
}
requestData = data;
this._stripe.getClientUserAgent((clientUserAgent) => {
var _a, _b;
const apiVersion = this._stripe.getApiField('version');
const headers = this._makeHeaders(auth, requestData.length, apiVersion, clientUserAgent, method, (_a = options.headers) !== null && _a !== void 0 ? _a : null, (_b = options.settings) !== null && _b !== void 0 ? _b : {});
const headers = this._makeHeaders({
contentType: apiMode == 'v2'
? 'application/json'
: 'application/x-www-form-urlencoded',
contentLength: requestData.length,
apiVersion: apiVersion,
clientUserAgent,
method,
userSuppliedHeaders: options.headers,
userSuppliedSettings: options.settings,
stripeAccount: apiMode == 'v2' ? null : this._stripe.getApiField('stripeAccount'),
stripeContext: apiMode == 'v2' ? this._stripe.getApiField('stripeContext') : null,
apiMode: apiMode,
});
makeRequest(apiVersion, headers, 0);
});
};
@@ -346,7 +440,14 @@ export class RequestSender {
requestDataProcessor(method, data, options.headers, prepareAndMakeRequest);
}
else {
prepareAndMakeRequest(null, stringifyRequestData(data || {}));
let stringifiedData;
if (apiMode == 'v2') {
stringifiedData = data ? jsonStringifyRequestData(data) : '';
}
else {
stringifiedData = queryStringifyRequestData(data || {}, apiMode);
}
prepareAndMakeRequest(null, stringifiedData);
}
}
}