Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Public Beta
Browse files Browse the repository at this point in the history
This changeset prepares Bloombox JS for public beta. Here's what's
cooking:

- [x] Configuration structure that is extensible and makes sense
- [x] No ability to mutate configuration outside of proper
      channels
- [ ] Improvements to the docs, especially w.r.t. enums
- [ ] Some kind of formal unit testing
- [ ] Better hosting and a proper universal redirect
- [ ] Fix the debug build and cleanup the build chain
- [ ] Buildout the ability to fetch and cache the menu, in entirety
      or by section.
  - [ ] Figure out some caching mechanism
- [ ] Allow subscribing to menu changes
  - [ ] Embedding Firebase would be useful here
- [ ] Basic integrations
  - [ ] Google Analytics
    - [ ] Relay for non-internal events to GA
    - [ ] Prep/wiring to hook commercial events up
  - [ ] Keen IO
    - [ ] Relay for non-internal events
  - [ ] Segment IO
    - [ ] Relay for non-internal events
- [ ] Internal support code
  - [ ] Error reporting to Stackdriver
  - [ ] Updates to internal telemetry events, if any
  - [ ] Prep NPM etc. for distribution
  • Loading branch information
Sam Gammon committed Nov 28, 2017
1 parent c06ab5e commit a9de574
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .tpl/README.md.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,9 @@ Publishing the library (GCS CDN permissions required):
```
make publish
```

##### Licensing

This library was made and is managed with <3 by Bloombox, a subsidiary of Momentum Ideas, Co., from Sacramento,
California. Bloombox JS is distributed under the Apache License v2, which is enclosed herein as `LICENSE.txt`. Third
party license notices, including ones from MochiKit and Google, via the Closure Authors.
7 changes: 3 additions & 4 deletions .tpl/license.txt.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
*
* Bloombox JS __VERSION__
*
* Copyright (c) 2017, Momentum Ideas, Co. All rights reserved.
* Copyright (c) 2017, Momentum Ideas, Co. All rights reserved. Distributed under the Apache License, Version 2.0,
* last revised January 2004 and enclosed in this codebase in 'LICENSE.txt'. Also, see third-party license notices
* in 'NOTICE.txt'.
*
* Portions of this code are from MochiKit, received by Momentum Ideas under the MIT license via The Closure Authors.
* All remaining Closure library code is Copyright 2005-2009 The Closure Authors.
*/

File renamed without changes.
3 changes: 3 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Portions of this code are from MochiKit, received by Momentum Ideas under the MIT license via The Closure Authors.
All remaining Closure library code is Copyright 2005-2009 The Closure Authors.
140 changes: 140 additions & 0 deletions src/base/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

/**
* Bloombox JS: Config
*
* @fileoverview Provides initial boot code for Bloombox JS.
*/

/*global goog */

goog.provide('bloombox.config.active');
goog.provide('bloombox.config.buildDefault');
goog.provide('bloombox.config.configure');

goog.require('bloombox.DEBUG');
goog.require('bloombox.VERSION');

goog.require('bloombox.config.integration.GoogleAnalyticsConfig');
goog.require('bloombox.config.integration.KeenIOConfig');
goog.require('bloombox.config.integration.SegmentConfig');


/**
* Specifies the structure of Bloombox JS's global configuration object.
*
* @public
* @nocollapse
* @typedef {{key: ?string,
* partner: ?string,
* location: ?string,
* channel: ?string,
* integrations: bloombox.config.JSIntegrationConfig,
* endpoints: {
* shop: ?string,
* telemetry: ?string}}}
*/
bloombox.config.JSConfig;


/**
* Specifies the structure of configuration related to integrations that plug
* into the JS client. As of this writing, that includes Google Analytics, Keen
* IO, and Segment.
*
* @public
* @nocollapse
* @typedef {{google: {
* analytics: bloombox.config.integrations.GoogleAnalyticsConfig},
* segment: bloombox.config.integrations.SegmentConfig,
* keen: bloombox.config.integrations.KeenIOConfig}}
*/
bloombox.config.JSIntegrationConfig;


/**
* Reference to the active global configuration.
*
* @type {bloombox.config.JSConfig}
* @private
*/
bloombox.config._ACTIVE_CONFIG_ = bloombox.config.buildDefault();


/**
* @typedef {bloombox.config.integrations.GoogleAnalyticsConfig}
* @package
*/
let GoogleAnalyticsConfig;


/**
* @typedef {bloombox.config.integrations.SegmentConfig}
* @package
*/
let SegmentConfig;


/**
* @typedef {bloombox.config.integrations.KeenIOConfig}
* @package
*/
let KeenIOConfig;


/**
* Resolve the active configuration object.
*
* @return {bloombox.config.JSConfig} Active JS config.
* @public
*/
bloombox.config.buildDefault = function() {
return {
key: null,
partner: null,
location: null,
channel: null,
endpoints: {
shop: null,
telemetry: null
},
integrations: {
google: {
analytics: /** @type {GoogleAnalyticsConfig} */ ({
enabled: false,
trackingId: null
})
},
segment: /** @type {SegmentConfig} */ ({
writeKey: null
}),
keen: /** @type {KeenIOConfig} */ ({
projectId: null,
writeKey: null
})
}
};
};


/**
* Resolve the active configuration object.
*
* @param {bloombox.config.JSConfig} config Replace the active JS config.
* @public
*/
bloombox.config.configure = function(config) {
if (Object.isFrozen && !Object.isFrozen(config))
Object.freeze(config);
bloombox.config._ACTIVE_CONFIG_ = config;
};


/**
* Resolve the active configuration object.
*
* @return {bloombox.config.JSConfig} Active JS config.
* @public
*/
bloombox.config.active = function() {
return bloombox.config._ACTIVE_CONFIG_;
};
22 changes: 22 additions & 0 deletions src/base/config/integration/ga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/**
* Bloombox JS Config: Google Analytics
*
* @fileoverview Provides configuration structure for the Google Analytics
* integration layer with Bloombox JS.
*/

/*global goog */

goog.provide('bloombox.config.integration.GoogleAnalyticsConfig');


/**
* Specifies configuration structure for Google Analytics integration features.
*
* @public
* @nocollapse
* @typedef {{enabled: boolean,
* trackingId: ?Array<string>}}
*/
bloombox.config.integration.GoogleAnalyticsConfig;
23 changes: 23 additions & 0 deletions src/base/config/integration/keen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/**
* Bloombox JS Config: Keen IO
*
* @fileoverview Provides configuration structure for the Keen IO integration
* layer with Bloombox JS.
*/

/*global goog */

goog.provide('bloombox.config.integration.KeenIOConfig');


/**
* Specifies configuration structure for Keen IO integration features.
*
* @public
* @nocollapse
* @typedef {{enabled: boolean,
* projectId: string,
* writeKey: string}}
*/
bloombox.config.integration.KeenIOConfig;
22 changes: 22 additions & 0 deletions src/base/config/integration/segment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/**
* Bloombox JS Config: Segment IO
*
* @fileoverview Provides configuration structure for the Segment IO integration
* layer with Bloombox JS.
*/

/*global goog */

goog.provide('bloombox.config.integration.SegmentConfig');


/**
* Specifies configuration structure for Segment IO integration features.
*
* @public
* @nocollapse
* @typedef {{enabled: boolean,
* writeKey: string}}
*/
bloombox.config.integration.SegmentConfig;
30 changes: 2 additions & 28 deletions src/base/init.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@

/**
* Bloombox JS
* Bloombox JS: Init
*
* @fileoverview Provides initial boot code for Bloombox JS.
* @fileoverview Initial boot code for Bloombox JS.
*/

/*global goog */

goog.provide('bloombox.DEBUG');
goog.provide('bloombox.VERSION');
goog.provide('bloombox.config');

// force-load closure and closure UI libraries
goog.require('goog.proto');
goog.require('goog.ui.INLINE_BLOCK_CLASSNAME');


Expand All @@ -33,27 +31,3 @@ bloombox.DEBUG = true;
* @export
*/
bloombox.VERSION = 'v1.0.0';


/**
* Holds global configuration for the library.
*
* @nocollapse
* @type {{key: ?string,
* partner: ?string,
* location: ?string,
* channel: ?string,
* endpoints: {
* shop: ?string,
* telemetry: ?string}}}
*/
bloombox.config = {
key: null,
partner: null,
location: null,
channel: null,
endpoints: {
shop: null,
telemetry: null
}
};
2 changes: 1 addition & 1 deletion src/base/logging.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Bloombox: Logging
* Bloombox JS: Logging
*
* @fileoverview Provides logging tools.
*/
Expand Down
11 changes: 6 additions & 5 deletions src/base/rpc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Bloombox: RPC Tooling
* Bloombox JS: RPC Internals
*
* @fileoverview Provides low-level tools for RPCs.
*/
Expand All @@ -12,7 +12,7 @@ goog.provide('bloombox.rpc.RPCException');

goog.require('bloombox.DEBUG');
goog.require('bloombox.VERSION');
goog.require('bloombox.config');
goog.require('bloombox.config.active');

goog.require('bloombox.logging.error');
goog.require('bloombox.logging.log');
Expand Down Expand Up @@ -90,9 +90,10 @@ bloombox.rpc.RPCException.prototype.toString = function() {
* @public
*/
bloombox.rpc.RPC = function RPC(httpMethod, endpoint, opt_payload, opt_keep) {
let apiKey = bloombox.config.key;
let partner = bloombox.config.partner;
let location = bloombox.config.location;
let config = bloombox.config.active();
let apiKey = config.key;
let partner = config.partner;
let location = config.location;
if (!apiKey || !(typeof apiKey === 'string'))
throw new bloombox.rpc.RPCException('API key could not be resolved.' +
' Please call `setup` before any RPC methods.');
Expand Down
7 changes: 3 additions & 4 deletions src/license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
*
* Bloombox JS v1.0.0-alpha10
*
* Copyright (c) 2017, Momentum Ideas, Co. All rights reserved.
* Copyright (c) 2017, Momentum Ideas, Co. All rights reserved. Distributed under the Apache License, Version 2.0,
* last revised January 2004 and enclosed in this codebase in 'LICENSE.txt'. Also, see third-party license notices
* in 'NOTICE.txt'.
*
* Portions of this code are from MochiKit, received by Momentum Ideas under the MIT license via The Closure Authors.
* All remaining Closure library code is Copyright 2005-2009 The Closure Authors.
*/

7 changes: 4 additions & 3 deletions src/shop/accounts/enroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ goog.provide('bloombox.shop.enroll.Enrollment');
goog.provide('bloombox.shop.enroll.EnrollmentException');
goog.provide('bloombox.shop.enroll.EnrollmentSource');

goog.require('bloombox.config');
goog.require('bloombox.config.active');

goog.require('bloombox.identity.ConsumerProfile');
goog.require('bloombox.identity.ContactInfo');
Expand Down Expand Up @@ -185,8 +185,9 @@ bloombox.shop.enroll.Enrollment.prototype.enableDryRun = function() {
* @export
*/
bloombox.shop.enroll.Enrollment.prototype.send = function(callback) {
let partner = bloombox.config.partner;
let location = bloombox.config.location;
let config = bloombox.config.active();
let partner = config.partner;
let location = config.location;

if (!partner || !location) {
bloombox.logging.error('Partner or location code is not defined.');
Expand Down
5 changes: 3 additions & 2 deletions src/shop/accounts/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ bloombox.shop.verify = function(email,
throw new bloombox.shop.order.VerifyException(
'Email was found to be empty or invalid, cannot verify.');

let partner = bloombox.config.partner;
let location = bloombox.config.location;
let config = bloombox.config.active();
let partner = config.partner;
let location = config.location;

if (!partner || !location) {
bloombox.logging.error('Partner or location code is not defined.');
Expand Down
7 changes: 4 additions & 3 deletions src/shop/info/shopinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ goog.provide('bloombox.shop.ShopInfoException');
goog.provide('bloombox.shop.ShopStatus');
goog.provide('bloombox.shop.info');

goog.require('bloombox.config');
goog.require('bloombox.config.active');

goog.require('bloombox.logging.error');
goog.require('bloombox.logging.info');
Expand Down Expand Up @@ -69,8 +69,9 @@ bloombox.shop.ShopInfoException = function ShopInfoException(message) {
*/
bloombox.shop.info = function(callback) {
// load partner and location codes
let partnerCode = bloombox.config.partner;
let locationCode = bloombox.config.location;
let config = bloombox.config.active();
let partnerCode = config.partner;
let locationCode = config.location;

if (!partnerCode ||
!(typeof partnerCode === 'string' && partnerCode.length > 1) ||
Expand Down
Loading

0 comments on commit a9de574

Please sign in to comment.