 RESIN_SDK_HAS_USED_SHARED_OPTIONS = 'RESIN_SDK_HAS_USED_SHARED_OPTIONS'
 RESIN_SDK_HAS_SET_SHARED_OPTIONS = 'RESIN_SDK_HAS_SET_SHARED_OPTIONS'
 
+# Use window (web)/self (web worker)/global (node) as appropriate
+globalEnv = if typeof window != 'undefined'
+	window
+else if typeof self != 'undefined'
+	self
+else if typeof global != 'undefined'
+	global
+else null
+
 ###*
 # @namespace resin
 # @description

# });
###
getSdk.setSharedOptions = (opts) ->
	root = if window? then window else global

	if root[RESIN_SDK_HAS_USED_SHARED_OPTIONS]
		console.error('Shared SDK options have already been used. You may have a race condition in your code.')

	if root[RESIN_SDK_HAS_SET_SHARED_OPTIONS]
		console.error('Shared SDK options have already been set. You may have a race condition in your code.')

	root[RESIN_SDK_SHARED_OPTIONS] = opts
	root[RESIN_SDK_HAS_SET_SHARED_OPTIONS] = true

###*
# @summary Create an SDK instance using shared default options

# const sdk = resin.fromSharedOptions();
###
getSdk.fromSharedOptions = ->
	sharedOpts = globalEnv[RESIN_SDK_SHARED_OPTIONS]

	globalEnv[RESIN_SDK_HAS_USED_SHARED_OPTIONS] = true

	getSdk(sharedOpts)

