@mparticle/web-sdk 2.26.10 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/uploaders.ts CHANGED
@@ -33,12 +33,25 @@ export class XHRUploader extends AsyncUploader {
33
33
  public async upload(fetchPayload: fetchPayload): Promise<Response> {
34
34
  const response: Response = await this.makeRequest(
35
35
  this.url,
36
- fetchPayload.body
36
+ fetchPayload.body,
37
+ fetchPayload.method as 'post' | 'get'
37
38
  );
38
39
  return response;
39
40
  }
40
41
 
41
- private async makeRequest(url: string, data: string): Promise<Response> {
42
+ // XHR Ready States
43
+ // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
44
+ // 0 UNSENT open() has not been called yet.
45
+ // 1 OPENED send() has been called.
46
+ // 2 HEADERS_RECEIVED send() has been called, and headers and status are available.
47
+ // 3 LOADING Downloading; responseText holds partial data.
48
+ // 4 DONE The operation is complete.
49
+
50
+ private async makeRequest(
51
+ url: string,
52
+ data: string,
53
+ method: 'post' | 'get' = 'post'
54
+ ): Promise<Response> {
42
55
  const xhr: XMLHttpRequest = new XMLHttpRequest();
43
56
  return new Promise((resolve, reject) => {
44
57
  xhr.onreadystatechange = () => {
@@ -46,13 +59,13 @@ export class XHRUploader extends AsyncUploader {
46
59
 
47
60
  // Process the response
48
61
  if (xhr.status >= 200 && xhr.status < 300) {
49
- resolve((xhr as unknown) as Response);
62
+ resolve(xhr as unknown as Response);
50
63
  } else {
51
64
  reject(xhr);
52
65
  }
53
66
  };
54
67
 
55
- xhr.open('post', url);
68
+ xhr.open(method, url);
56
69
  xhr.send(data);
57
70
  });
58
71
  }