Skip to content

Commit

Permalink
v0.1.388
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 601829646
  • Loading branch information
Google Earth Engine Authors authored and naschmitz committed Jan 31, 2024
1 parent 8fee1d9 commit cdfe00b
Show file tree
Hide file tree
Showing 33 changed files with 1,704 additions and 841 deletions.
558 changes: 279 additions & 279 deletions javascript/build/ee_api_js.js

Large diffs are not rendered by default.

357 changes: 133 additions & 224 deletions javascript/build/ee_api_js_debug.js

Large diffs are not rendered by default.

401 changes: 155 additions & 246 deletions javascript/build/ee_api_js_npm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/package.json
@@ -1,6 +1,6 @@
{
"name": "@google/earthengine",
"version": "0.1.386",
"version": "0.1.388",
"description": "JavaScript client for Google Earth Engine API.",
"author": "Google LLC",
"license": "Apache-2.0",
Expand Down
83 changes: 43 additions & 40 deletions javascript/src/apiclient.js
Expand Up @@ -4,7 +4,6 @@
goog.module('ee.apiclient');
goog.module.declareLegacyNamespace();

const GoogConst = goog.require('goog.string.Const');
const Throttle = goog.require('goog.async.Throttle');
const Uri = goog.require('goog.Uri');
const XhrIo = goog.require('goog.net.XhrIo');
Expand All @@ -25,7 +24,7 @@ const {trustedResourceUrl} = goog.require('safevalues');
/** @namespace */
const apiclient = {};

const API_CLIENT_VERSION = '0.1.386';
const API_CLIENT_VERSION = '0.1.388';

exports.VERSION = apiVersion.VERSION;
exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
Expand Down Expand Up @@ -533,7 +532,6 @@ apiclient.setAuthToken = function(
}
} else {
apiclient.ensureAuthLibLoaded_(function() {
goog.global['gapi']['client']['setToken'](tokenObject);
if (callback) {
callback();
}
Expand All @@ -560,7 +558,6 @@ apiclient.refreshAuthToken = function(success, error, onImmediateFailed) {
// Set up auth options.
const authArgs = {
'client_id': String(apiclient.authClientId_),
'immediate': true,
'scope': apiclient.authScopes_.join(' '),
'plugin_name': 'earthengine',
};
Expand All @@ -576,7 +573,6 @@ apiclient.refreshAuthToken = function(success, error, onImmediateFailed) {
// Refresh the library auth token and handle error propagation.
apiclient.ensureAuthLibLoaded_(function() {
try {
goog.global['gapi']['client']['setToken'](result);
apiclient.handleAuthResult_(success, error, result);
} catch (e) {
error(e.toString());
Expand All @@ -595,8 +591,8 @@ apiclient.refreshAuthToken = function(success, error, onImmediateFailed) {

/**
* Sets the current OAuth token refresher. By default, automatically set to
* gapi.auth.authorize() after the auth library loads. Set to null to disable
* token refreshing.
* Google Identity Services' callback triggered by `requestAccessToken()` after
* the auth library loads. Set to null to disable token refreshing.
*
* @param {?function(!apiclient.AuthArgs, function(!apiclient.AuthResponse))}
* refresher A function that takes as input 1) auth arguments and
Expand Down Expand Up @@ -1120,50 +1116,50 @@ apiclient.handleResponse_ = function(


/**
* Ensures that the Google API Client Library for JavaScript is loaded.
* Ensures that the Google Identity Services (GIS) libraries are loaded.
* @param {function()} callback The function to call when the library is ready.
* @private
*/
apiclient.ensureAuthLibLoaded_ = function(callback) {
const done = function() {
// Speed up auth request by using CORS instead of an iframe.
goog.global['gapi']['config']['update']('client/cors', true);
if (!apiclient.authTokenRefresher_) {
apiclient.setAuthTokenRefresher(goog.global['gapi']['auth2']['authorize']);
apiclient.setAuthTokenRefresher(function(authArgs, refresherCallback) {
/** @type {!TokenClient} */
const tokenClient =
goog.global['google']['accounts']['oauth2']['initTokenClient']({
'client_id': authArgs.client_id,
'callback': refresherCallback,
'scope': authArgs.scope,
});
tokenClient.requestAccessToken();
});
}
callback();
};
if (goog.isObject(goog.global['gapi']) &&
goog.isObject(goog.global['gapi']['auth2']) &&
typeof goog.global['gapi']['auth2']['authorize'] === 'function') {
done();
} else {
// The library is not loaded; load it now.
let callbackName = Date.now().toString(36);
while (callbackName in goog.global) {
callbackName += '_';
}
goog.global[callbackName] = function() {
delete goog.global[callbackName];
const loadGis = function() {
if (goog.isObject(goog.global['default_gsi'])) {
done();
};
jsloader.safeLoad(
trustedResourceUrl`https://apis.google.com/js/client.js?onload=${
callbackName}`);
}
} else {
jsloader
.safeLoad(trustedResourceUrl`https://accounts.google.com/gsi/client`)
.addCallback(done);
}
};
loadGis();
};


/**
* Handles the result of gapi.auth.authorize(), storing the auth token on
* success and setting up a refresh timeout.
* Handles the result of an AuthResponse, storing the auth token on success and
* setting up a refresh timeout.
*
* @param {function()|undefined} success The function to call if token refresh
* succeeds.
* @param {function(string)|undefined} error The function to call if auth fails,
* passing the error message.
* @param {!apiclient.AuthResponse} result The result object produced by
* a token refresher such as gapi.auth.authorize().
* @param {!apiclient.AuthResponse} result The result object produced by a token
* refresher such as Google Identity Services' callback triggered by
* `requestAccessToken()`.
* @private
*/
apiclient.handleAuthResult_ = function(success, error, result) {
Expand Down Expand Up @@ -1547,13 +1543,6 @@ apiclient.CLOUD_PLATFORM_SCOPE_ =
apiclient.DEFAULT_AUTH_SCOPES_ =
[apiclient.AUTH_SCOPE_, apiclient.CLOUD_PLATFORM_SCOPE_];

/**
* The URL of the Google APIs Client Library.
* @private @const {!GoogConst}
*/
apiclient.AUTH_LIBRARY_URL_ = GoogConst.from(
'https://apis.google.com/js/client.js?onload=%{onload}');


/**
* The OAuth scope for Cloud Storage.
Expand Down Expand Up @@ -1676,7 +1665,8 @@ apiclient.AuthArgs = class {
this.client_id;

/**
* @export {boolean}
* @deprecated Immediate field is unused.
* @export {boolean|undefined}
*/
this.immediate;

Expand All @@ -1687,6 +1677,19 @@ apiclient.AuthArgs = class {
}
};

/**
* A token client to provide access tokens. For details, see
* https://developers.google.com/identity/oauth2/web/reference/js-reference#TokenClient.
* @record @struct
*/
class TokenClient {
constructor() {
/**
* @export {function():void}
*/
this.requestAccessToken;
}
}

/**
* The result of a token refresh. Passed by the token refresher to the callback
Expand Down
13 changes: 7 additions & 6 deletions javascript/src/data.js
Expand Up @@ -195,13 +195,14 @@ ee.data.authenticate = function(
* @export
*/
ee.data.authenticateViaPopup = function(opt_success, opt_error) {
goog.global['gapi']['auth2']['authorize'](
{
const tokenClient =
goog.global['google']['accounts']['oauth2']['initTokenClient']({
'client_id': ee.apiclient.getAuthClientId(),
'immediate': false,
'scope': ee.apiclient.getAuthScopes().join(' ')
},
goog.partial(ee.apiclient.handleAuthResult, opt_success, opt_error));
'callback':
goog.partial(ee.apiclient.handleAuthResult, opt_success, opt_error),
'scope': ee.apiclient.getAuthScopes().join(' '),
});
tokenClient.requestAccessToken();
};


Expand Down
3 changes: 1 addition & 2 deletions javascript/src/examples/Demos/TerrainVisualization.js
Expand Up @@ -2,7 +2,7 @@
// a custom visualization of topography.

// Load a global elevation image.
var elev = ee.Image('USGS/GMTED2010');
var elev = ee.Image('USGS/GMTED2010').select('be75');

// Zoom to an area of interest.
Map.setCenter(-121.069, 50.709, 6);
Expand Down Expand Up @@ -44,4 +44,3 @@ var v = shade.divide(255);
// Note the cast to byte in order to export the image correctly.
var rgb = hs.addBands(v).hsvToRgb().multiply(255).byte();
Map.addLayer(rgb, {}, 'styled');

20 changes: 19 additions & 1 deletion python/ee/__init__.py
@@ -1,6 +1,6 @@
"""The EE Python library."""

__version__ = '0.1.386'
__version__ = '0.1.388'

# Using lowercase function naming to match the JavaScript names.
# pylint: disable=g-bad-name
Expand All @@ -27,8 +27,11 @@
from .blob import Blob
from .collection import Collection
from .computedobject import ComputedObject
from .confusionmatrix import ConfusionMatrix
from .customfunction import CustomFunction
from .daterange import DateRange
from .dictionary import Dictionary
from .ee_array import Array
from .ee_date import Date
from .ee_exception import EEException
from .ee_list import List
Expand All @@ -45,7 +48,10 @@
from .image import Image
from .imagecollection import ImageCollection
from .join import Join
from .model import Model
from .pixeltype import PixelType
from .projection import Projection
from .reducer import Reducer
from .serializer import Serializer
from .terrain import Terrain

Expand Down Expand Up @@ -159,9 +165,12 @@ def Initialize(

# Initialize the dynamically loaded functions on the objects that want them.
ApiFunction.initialize()
Array.initialize()
Blob.initialize()
Collection.initialize()
ConfusionMatrix.initialize()
Date.initialize()
DateRange.initialize()
Dictionary.initialize()
Element.initialize()
ErrorMargin.initialize()
Expand All @@ -173,8 +182,11 @@ def Initialize(
ImageCollection.initialize()
Join.initialize()
List.initialize()
Model.initialize()
Number.initialize()
PixelType.initialize()
Projection.initialize()
Reducer.initialize()
String.initialize()
Terrain.initialize()

Expand All @@ -191,8 +203,11 @@ def Reset() -> None:
ApiFunction.reset()
Element.reset() # Must be before Collection.
Collection.reset() # Must be before FeatureCollection and ImageCollection.
Array.reset()
Blob.reset()
ConfusionMatrix.reset()
Date.reset()
DateRange.reset()
Dictionary.reset()
ErrorMargin.reset()
Feature.reset()
Expand All @@ -203,8 +218,11 @@ def Reset() -> None:
ImageCollection.reset()
Join.reset()
List.reset()
Model.reset()
Number.reset()
PixelType.reset()
Projection.reset()
Reducer.reset()
String.reset()
Terrain.reset()

Expand Down
20 changes: 10 additions & 10 deletions python/ee/blob.py
Expand Up @@ -37,25 +37,25 @@ def __init__(self, url: Union[str, computedobject.ComputedObject]):
"""
self.initialize()

if isinstance(url, computedobject.ComputedObject):
args: Dict[str, Any] = {'url': url}
func = apifunction.ApiFunction(self.name())

if isinstance(url, str):
if not url.startswith('gs://'):
raise ValueError(f'{self.name()} url must start with "gs://": "{url}"')

elif isinstance(url, computedobject.ComputedObject):
if self.is_func_returning_same(url):
# If it is a call that is already returning a Blob, just cast.
super().__init__(url.func, url.args, url.varName)
return

super().__init__(apifunction.ApiFunction(self.name()), {'url': url})
return

if not isinstance(url, str):
else:
raise ValueError(
f'{self.name()} url must be a string: {type(url)} -> "{url}"'
)
if not url.startswith('gs://'):
raise ValueError(f'{self.name()} url must start with "gs://": "{url}"')

args: Dict[str, Any] = {'url': url}
func = apifunction.ApiFunction(self.name())
super().__init__(func, args)
super().__init__(func, func.promoteArgs(args))

@classmethod
def initialize(cls) -> None:
Expand Down

0 comments on commit cdfe00b

Please sign in to comment.