@google/earthengine 0.1.418 → 0.1.419

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/earthengine",
3
- "version": "0.1.418",
3
+ "version": "0.1.419",
4
4
  "description": "JavaScript client for Google Earth Engine API.",
5
5
  "author": "Google LLC",
6
6
  "license": "Apache-2.0",
package/src/apiclient.js CHANGED
@@ -24,7 +24,7 @@ const {trustedResourceUrl} = goog.require('safevalues');
24
24
  /** @namespace */
25
25
  const apiclient = {};
26
26
 
27
- const API_CLIENT_VERSION = '0.1.418';
27
+ const API_CLIENT_VERSION = '0.1.419';
28
28
 
29
29
  exports.VERSION = apiVersion.VERSION;
30
30
  exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
@@ -119,6 +119,12 @@ const simpleCorsAllowedHeaders: string[] = [
119
119
 
120
120
  const simpleCorsAllowedMethods: string[] = ['GET', 'HEAD', 'POST'];
121
121
 
122
+ const simpleCorsAllowedContentTypes: readonly string[] = [
123
+ 'application/x-www-form-urlencoded',
124
+ 'multipart/form-data',
125
+ 'text/plain',
126
+ ];
127
+
122
128
  /**
123
129
  * Note: This function only works for One Platform APIs.
124
130
  * Manipulates the request options such that it will not trigger a CORS
@@ -149,12 +155,19 @@ export function bypassCorsPreflight(params: MakeRequestParams) {
149
155
  const unsafeHeaders: {[key: string]: string} = {};
150
156
  let hasUnsafeHeaders = false;
151
157
  let hasContentType = false;
158
+ let hasSafeContentType = false;
152
159
 
153
160
  if (params.headers) {
154
161
  hasContentType = params.headers['Content-Type'] != null;
155
162
  for (const [key, value] of Object.entries(params.headers)) {
156
163
  if (simpleCorsAllowedHeaders.includes(key)) {
157
164
  safeHeaders[key] = value;
165
+ } else if (
166
+ key === 'Content-Type' &&
167
+ simpleCorsAllowedContentTypes.includes(value)
168
+ ) {
169
+ safeHeaders[key] = value;
170
+ hasSafeContentType = true;
158
171
  } else {
159
172
  unsafeHeaders[key] = value;
160
173
  hasUnsafeHeaders = true;
@@ -177,7 +190,9 @@ export function bypassCorsPreflight(params: MakeRequestParams) {
177
190
  unsafeHeaders['Content-Type'] = 'application/json';
178
191
  hasUnsafeHeaders = true;
179
192
  }
180
- safeHeaders['Content-Type'] = 'text/plain';
193
+ if (!hasSafeContentType) {
194
+ safeHeaders['Content-Type'] = 'text/plain';
195
+ }
181
196
  }
182
197
 
183
198
  if (hasUnsafeHeaders) {
@@ -172,6 +172,22 @@ describe('bypassCorsPreflight', () => {
172
172
  expect(params.queryParams).toEqual({});
173
173
  });
174
174
 
175
+ it('handles simple cors headers', () => {
176
+ const params: MakeRequestParams = {
177
+ path: 'v1/whatever',
178
+ httpMethod: 'GET',
179
+ methodId: 'someservice.whatever.get',
180
+ headers: {
181
+ 'Content-Type': 'application/x-www-form-urlencoded',
182
+ },
183
+ };
184
+ bypassCorsPreflight(params);
185
+ expect(params.headers).toEqual({
186
+ 'Content-Type': 'application/x-www-form-urlencoded',
187
+ });
188
+ expect(params.httpMethod).toEqual('GET');
189
+ });
190
+
175
191
  it('handles would-trigger-preflight cors headers', () => {
176
192
  const params: MakeRequestParams = {
177
193
  path: 'v1/whatever',