Skip to content

Commit

Permalink
feat: remove client id from required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bookernath committed Aug 1, 2019
1 parent 9b4c8f3 commit 0cbc093
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
jspm_packages
node_modules
npm-debug.log

.DS_Store
1 change: 0 additions & 1 deletion bin/stencil-start
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
9 changes: 0 additions & 9 deletions lib/stencil-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 6 additions & 6 deletions lib/stencil-push.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
18 changes: 9 additions & 9 deletions lib/theme-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -99,23 +99,23 @@ 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;
}
}

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,
Expand All @@ -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) => {
Expand Down Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 0 additions & 14 deletions server/lib/stencil-token.js

This file was deleted.

30 changes: 0 additions & 30 deletions server/lib/stencil-token.spec.js

This file was deleted.

7 changes: 2 additions & 5 deletions server/plugins/renderer/renderer.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/_mocks/bin/dotStencilFile.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"normalStoreUrl": "https://www.example.com",
"port": 4000,
"clientId": "clientId",
"accessToken": "accessToken"
}

0 comments on commit 0cbc093

Please sign in to comment.