From 4f37f584da447abd54ae448ee9d795d8acd52fa6 Mon Sep 17 00:00:00 2001 From: Cristian Douce Date: Fri, 9 Sep 2016 13:06:28 -0300 Subject: [PATCH] Introduce clientBaseUrl and languageBaseUrl options to deprecate assetsUrl. Fixes auth0/lock#576 --- README.md | 3 ++- src/core/client/settings.js | 4 ++-- src/core/index.js | 29 +++++++++++++++++++++++++---- src/core/remote_data.js | 2 +- src/i18n.js | 2 +- support/design/index.js | 2 +- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dba6071b9..18008527d 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,8 @@ var options = { #### Other options -- **assetsUrl {String}**: Will be used as the assets base url. Defaults to Auth0's the CDN url when `domain` has the format `*.auth0.com`. Otherwise, it defaults to `domain`. +- **clientBaseUrl {String}**: Overrides client settings base url. By default it uses Auth0's CDN url when `domain` has the format `*.auth0.com`. Otherwise, it uses the provided `domain`. +- **languageBaseUrl {String}**: Overrides the language source url for Auth0's provided translations. By default it uses to Auth0's CDN url `https://cdn.auth0.com`. #### Language Dictionary Specification diff --git a/src/core/client/settings.js b/src/core/client/settings.js index f39d92fe6..d51208b73 100644 --- a/src/core/client/settings.js +++ b/src/core/client/settings.js @@ -1,9 +1,9 @@ import { load } from '../../utils/cdn_utils'; -export function fetchClientSettings(clientID, assetsUrl, cb) { +export function fetchClientSettings(clientID, clientBaseUrl, cb) { load({ method: "setClient", - url: `${assetsUrl}/client/${clientID}.js?t${+new Date()}`, + url: `${clientBaseUrl}/client/${clientID}.js?t${+new Date()}`, check: o => o && o.id === clientID, cb: cb }); diff --git a/src/core/index.js b/src/core/index.js index 92611d538..fa449a030 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -21,7 +21,8 @@ const { export function setup(id, clientID, domain, options, hookRunner, emitEventFn) { let m = init(id, Immutable.fromJS({ - assetsUrl: extractAssetsUrlOption(options, domain), + clientBaseUrl: extractClientBaseUrlOption(options, domain), + languageBaseUrl: extractLanguageBaseUrlOption(options, domain), auth: extractAuthOptions(options), clientID: clientID, domain: domain, @@ -48,10 +49,13 @@ export function domain(m) { return get(m, "domain"); } -export function assetsUrl(m) { - return get(m, "assetsUrl"); +export function clientBaseUrl(m) { + return get(m, "clientBaseUrl"); } +export function languageBaseUrl(m) { + return get(m, "languageBaseUrl"); +} export function setSubmitting(m, value, error = "") { m = tset(m, "submitting", value); m = clearGlobalSuccess(m); @@ -201,7 +205,11 @@ export function withAuthOptions(m, opts) { .toJS(); } -function extractAssetsUrlOption(opts, domain) { +function extractClientBaseUrlOption(opts, domain) { + if (opts.clientBaseUrl && typeof opts.clientBaseUrl === "string") { + return opts.clientBaseUrl; + } + if (opts.assetsUrl && typeof opts.assetsUrl === "string") { return opts.assetsUrl; } @@ -220,6 +228,19 @@ function extractAssetsUrlOption(opts, domain) { } } +function extractLanguageBaseUrlOption(opts, domain) { + if (opts.languageBaseUrl && typeof opts.languageBaseUrl === "string") { + return opts.languageBaseUrl; + } + + if (opts.assetsUrl && typeof opts.assetsUrl === "string") { + return opts.assetsUrl; + } + + return "https://cdn.auth0.com" +} + + export function render(m) { return tset(m, "render", true); } diff --git a/src/core/remote_data.js b/src/core/remote_data.js index cde521645..bec9fc9ad 100644 --- a/src/core/remote_data.js +++ b/src/core/remote_data.js @@ -8,7 +8,7 @@ import sync, { isSuccess } from '../sync'; export function syncRemoteData(m) { m = sync(m, "client", { - syncFn: (m, cb) => fetchClientSettings(l.clientID(m), l.assetsUrl(m), cb), + syncFn: (m, cb) => fetchClientSettings(l.clientID(m), l.clientBaseUrl(m), cb), successFn: syncClientSettingsSuccess }); diff --git a/src/i18n.js b/src/i18n.js index e26547eee..5207f9a06 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -62,7 +62,7 @@ export function initI18n(m) { function syncLang(m, language, cb) { load({ method: "registerLanguageDictionary", - url: `${l.assetsUrl(m)}/js/lock/${__VERSION__}/${language}.js`, + url: `${l.languageBaseUrl(m)}/js/lock/${__VERSION__}/${language}.js`, check: str => str && str === language, cb: (err, _, dictionary) => { cb(err, dictionary); diff --git a/support/design/index.js b/support/design/index.js index 529d38a26..a84d8f7e1 100644 --- a/support/design/index.js +++ b/support/design/index.js @@ -73,7 +73,7 @@ WebAPI.prototype.parseHash = function(lockID, ...args) { return null; } -ClientSettings.fetchClientSettings = function(clientID, assetsUrl, cb) { +ClientSettings.fetchClientSettings = function(clientID, clientBaseUrl, cb) { // TODO: we should have propper settings for every configuration. const settings = { strategies: [