From 0cbc093eed6766ef5eb6e1a5f524badfdf73d9c5 Mon Sep 17 00:00:00 2001 From: Nathan Booker Date: Tue, 30 Jul 2019 21:57:25 -0500 Subject: [PATCH] feat: remove client id from required fields --- .gitignore | 2 +- bin/stencil-start | 1 - lib/stencil-init.js | 9 ------- lib/stencil-push.utils.js | 12 ++++----- lib/theme-api-client.js | 18 ++++++------- server/index.js | 1 - server/lib/stencil-token.js | 14 ---------- server/lib/stencil-token.spec.js | 30 ---------------------- server/plugins/renderer/renderer.module.js | 7 ++--- test/_mocks/bin/dotStencilFile.json | 1 - 10 files changed, 18 insertions(+), 77 deletions(-) delete mode 100644 server/lib/stencil-token.js delete mode 100644 server/lib/stencil-token.spec.js diff --git a/.gitignore b/.gitignore index 9b7d1a2a..18ef0a70 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ jspm_packages node_modules npm-debug.log - +.DS_Store diff --git a/bin/stencil-start b/bin/stencil-start index 7be4f105..f857d707 100755 --- a/bin/stencil-start +++ b/bin/stencil-start @@ -14,7 +14,6 @@ var Program = require('commander'); var Server = require('../server'); var ThemeConfig = require('../lib/theme-config'); var buildConfig = require('../lib/build-config'); -var stencilToken = require('../server/lib/stencil-token'); var Url = require('url'); var Wreck = require('wreck'); var jsonLint = require('../lib/json-lint'); diff --git a/lib/stencil-init.js b/lib/stencil-init.js index c269d16d..81be5889 100644 --- a/lib/stencil-init.js +++ b/lib/stencil-init.js @@ -99,15 +99,6 @@ internals.implementation = function(JspmAssembler, ThemeConfig, dotStencilFilePa } }, }, - { - type: 'input', - name: 'clientId', - message: 'What is your Stencil OAuth Client ID? (See https://stencil.bigcommerce.com/docs/creating-an-api-account)', - default: dotStencilFile && dotStencilFile.clientId, - filter: function(val) { - return val.trim(); - }, - }, { type: 'input', name: 'accessToken', diff --git a/lib/stencil-push.utils.js b/lib/stencil-push.utils.js index 867efc84..2e65f576 100644 --- a/lib/stencil-push.utils.js +++ b/lib/stencil-push.utils.js @@ -74,7 +74,7 @@ utils.getThemes = (options, callback) => { themeApiClient.getThemes({ accessToken: config.accessToken, apiHost: options.apiHost, - clientId: config.clientId, + clientId: 'stencil-cli', storeHash: options.storeHash, }, (error, result) => { if (error) { @@ -124,7 +124,7 @@ utils.uploadBundle = (options, callback) => { accessToken: config.accessToken, apiHost: options.apiHost, bundleZipPath: options.bundleZipPath, - clientId: config.clientId, + clientId: 'stencil-cli', storeHash: options.storeHash, }, (error, result) => { if (error) { @@ -187,7 +187,7 @@ utils.deleteThemesIfNecessary = (options, callback) => { themeApiClient.deleteThemeById(Object.assign({ accessToken: config.accessToken, apiHost: options.apiHost, - clientId: config.clientId, + clientId: 'stencil-cli', storeHash: options.storeHash, themeId, }, options), cb); @@ -245,7 +245,7 @@ utils.checkIfJobIsComplete = (options, callback) => { themeApiClient.getJob({ accessToken: config.accessToken, apiHost: options.apiHost, - clientId: config.clientId, + clientId: 'stencil-cli', storeHash: options.storeHash, bundleZipPath: options.bundleZipPath, jobId: options.jobId, @@ -285,7 +285,7 @@ utils.getVariations = (options, callback) => { themeApiClient.getVariationsByThemeId({ accessToken: options.accessToken, apiHost: options.apiHost, - clientId: options.clientId, + clientId: 'stencil-cli', themeId: options.themeId, storeHash: options.storeHash, }, (error, result) => { @@ -347,7 +347,7 @@ utils.requestToApplyVariation = (options, callback) => { themeApiClient.activateThemeByVariationId({ accessToken: options.accessToken, apiHost: options.apiHost, - clientId: options.clientId, + clientId: 'stencil-cli', storeHash: options.storeHash, variationId: options.variationId, }, (error, result) => { diff --git a/lib/theme-api-client.js b/lib/theme-api-client.js index e9c2766f..51b9276a 100644 --- a/lib/theme-api-client.js +++ b/lib/theme-api-client.js @@ -20,7 +20,7 @@ module.exports = themeApiClient; function activateThemeByVariationId(options, callback) { Wreck.post(`${options.apiHost}/stores/${options.storeHash}/v3/themes/actions/activate`, { headers: { - 'x-auth-client': options.clientId, + 'x-auth-client': 'stencil-cli', 'x-auth-token': options.accessToken, }, json: true, @@ -41,7 +41,7 @@ function activateThemeByVariationId(options, callback) { function deleteThemeById(options, callback) { Wreck.delete(`${options.apiHost}/stores/${options.storeHash}/v3/themes/${options.themeId}`, { headers: { - 'x-auth-client': options.clientId, + 'x-auth-client': 'stencil-cli', 'x-auth-token': options.accessToken, }, json: true, @@ -58,7 +58,7 @@ function getJob(options, callback) { const opts = { headers: { 'cache-control': 'no-cache', - 'x-auth-client': options.clientId, + 'x-auth-client': 'stencil-cli', 'x-auth-token': options.accessToken, }, json: true, @@ -99,9 +99,9 @@ function printErrorMessages(errors_array) { return false } - for (var i = 0; i < errors_array.length; i++) { + for (var i = 0; i < errors_array.length; i++) { try{ - console.log(errors_array[i].message.red + '\n'); + console.log(errors_array[i].message.red + '\n'); } catch(err) { continue; @@ -109,13 +109,13 @@ function printErrorMessages(errors_array) { } console.log('Please visit the troubleshooting page https://stencil.bigcommerce.com/docs/uploading-a-custom-theme'); - return true + return true } function getThemes(options, callback) { Wreck.get(`${options.apiHost}/stores/${options.storeHash}/v3/themes`, { headers: { - 'x-auth-client': options.clientId, + 'x-auth-client': 'stencil-cli', 'x-auth-token': options.accessToken, }, json: true, @@ -134,7 +134,7 @@ function getVariationsByThemeId(options, callback) { Wreck.get(`${options.apiHost}/stores/${options.storeHash}/v3/themes/${options.themeId}`, { json: true, headers: { - 'x-auth-client': options.clientId, + 'x-auth-client': 'stencil-cli', 'x-auth-token': options.accessToken, }, }, (err, res, payload) => { @@ -164,7 +164,7 @@ function postTheme(options, callback) { 'cache-control': 'no-cache', 'content-type': 'multipart/form-data', 'x-auth-token': options.accessToken, - 'x-auth-client': options.clientId, + 'x-auth-client': 'stencil-cli', }, json: true, method: 'POST', diff --git a/server/index.js b/server/index.js index 75df8f2f..80f67563 100644 --- a/server/index.js +++ b/server/index.js @@ -25,7 +25,6 @@ module.exports = (options, callback) => { config.plugins['./plugins/renderer/renderer.module'].useCache = options.useCache; config.plugins['./plugins/renderer/renderer.module'].username = options.dotStencilFile.username; config.plugins['./plugins/renderer/renderer.module'].token = options.dotStencilFile.token; - config.plugins['./plugins/renderer/renderer.module'].clientId = options.dotStencilFile.clientId; config.plugins['./plugins/renderer/renderer.module'].accessToken = options.dotStencilFile.accessToken; config.plugins['./plugins/renderer/renderer.module'].customLayouts = options.dotStencilFile.customLayouts; config.plugins['./plugins/renderer/renderer.module'].stencilEditorPort = options.stencilEditorPort; diff --git a/server/lib/stencil-token.js b/server/lib/stencil-token.js deleted file mode 100644 index 1868d803..00000000 --- a/server/lib/stencil-token.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - /** - * Simple function to create the needed base64 token for Stencil Authorization - * @param {string} username - * @param {string} token - */ - generate: function (username, token) { - if (!username || !token) { - throw new Error('Username/token required!'); - } - - return new Buffer(username + ':' + token).toString('base64'); - }, -}; diff --git a/server/lib/stencil-token.spec.js b/server/lib/stencil-token.spec.js deleted file mode 100644 index e36a41ef..00000000 --- a/server/lib/stencil-token.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -var Code = require('code'), - Lab = require('lab'), - lab = exports.lab = Lab.script(), - describe = lab.describe, - stencilToken = require('./stencil-token'), - expect = Code.expect, - it = lab.it; - -describe('stencilToken', function () { - var options = { - username: 'testUser', - token: '12345689DEADBEEF', - validToken: 'dGVzdFVzZXI6MTIzNDU2ODlERUFEQkVFRg==', - }; - - it('should return a base64 encoded string', function (done) { - expect(stencilToken.generate(options.username, options.token)).to.be.equal(options.validToken); - done(); - }); - - it('should return an error without credentials', function (done) { - var throws = function () { - stencilToken.generate(); - }; - - expect(throws).throw(Error); - - done(); - }); -}); diff --git a/server/plugins/renderer/renderer.module.js b/server/plugins/renderer/renderer.module.js index c93fc2e7..5a6381e7 100644 --- a/server/plugins/renderer/renderer.module.js +++ b/server/plugins/renderer/renderer.module.js @@ -13,7 +13,6 @@ const Responses = require('./responses/responses'); const TemplateAssembler = require('../../../lib/template-assembler'); const Url = require('url'); const Utils = require('../../lib/utils'); -const stencilToken = require('../../lib/stencil-token'); const Wreck = require('wreck'); const internals = { options: {}, @@ -441,11 +440,9 @@ internals.getHeaders = function (request, options, config) { 'accept-encoding': 'identity', }; - if (internals.options.clientId && internals.options.accessToken) { - headers['X-Auth-Client'] = internals.options.clientId; + if (internals.options.accessToken) { + headers['X-Auth-Client'] = 'stencil-cli'; headers['X-Auth-Token'] = internals.options.accessToken; - } else { - headers['Authorization'] = 'Basic ' + stencilToken.generate(internals.options.username, internals.options.token); } // Development diff --git a/test/_mocks/bin/dotStencilFile.json b/test/_mocks/bin/dotStencilFile.json index dd32de6a..ae0cea45 100644 --- a/test/_mocks/bin/dotStencilFile.json +++ b/test/_mocks/bin/dotStencilFile.json @@ -1,6 +1,5 @@ { "normalStoreUrl": "https://www.example.com", "port": 4000, - "clientId": "clientId", "accessToken": "accessToken" }