Skip to content

Commit

Permalink
Merge pull request #3 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[feat] Make Generics use this.app
  • Loading branch information
scott-wyatt authored Aug 4, 2018
2 parents 24eec54 + c0a3965 commit 6bc8962
Show file tree
Hide file tree
Showing 31 changed files with 105 additions and 112 deletions.
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2016 scott-wyatt <[email protected]> (https://cali-style.com)
Copyright (c) 2018 CST <[email protected]>
2018 Scott Wyatt <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 13 additions & 5 deletions lib/Generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { FabrixGeneric } from '@fabrix/fabrix/dist/common'

export class Generic extends FabrixGeneric {
private _app: FabrixApp
private _config: {[key: string]: any}

constructor (app: FabrixApp) {
constructor (app: FabrixApp, config) {
super(app)

if (!(app instanceof EventEmitter)) {
throw new Error('The "app" argument must be of type EventEmitter')
}
this._app = app
this._config = config
this.app.emit(`generic:${this.id}:constructed`, this)
}

Expand All @@ -40,10 +41,17 @@ export class Generic extends FabrixGeneric {
}

/**
* Return a reference to the Fabrix configuration map.
* Return a reference to the Adapter's config.
*/
get config () {
return this._config
}

/**
* Sets Adapter's config
*/
get config (): FabrixApp['config'] {
return this.app.config
set config (config) {
this._config = config
}


Expand Down
10 changes: 0 additions & 10 deletions lib/GenericsSpool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Spool } from '@fabrix/fabrix/dist/common'
import { Generics } from './generics'

import { Validator } from './validator'

Expand Down Expand Up @@ -50,15 +49,6 @@ export class GenericsSpool extends Spool {
])
}

/**
* Configure
*/
async configure () {
return Promise.all([
Generics.configure(this.app)
])
}

async unload() {
return Promise.all([])
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/DataStoreGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class DataStoreGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.data_store_provider.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.data_store_provider.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.data_store_provider.config'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/EmailGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class EmailGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.email_provider.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.email_provider.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.email_provider.config'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/FulfillmentGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class FulfillmentGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.fulfillment_provider.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.fulfillment_provider.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.fulfillment_provider.config'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/GeolocationGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class GeolocationGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.geolocation_provider.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.geolocation_provider.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.geolocation_provider.config'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/ImageGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ImageGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.image_processor.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.image_processor.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.image_processor.config'))
}
}

2 changes: 1 addition & 1 deletion lib/api/services/PaymentGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class PaymentGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.payment_processor.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.payment_processor.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.payment_processor.config'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/RenderGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class RenderGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.render_service.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.render_service.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.render_service.config'))
}
/**
*
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/ShippingGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ShippingGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.shipping_provider.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.shipping_provider.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.shipping_provider.config'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/api/services/TaxGenericService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class TaxGenericService extends Service {
*/
private _init(generic) {
const Adapter = generic ? generic.adapter : this.app.config.get('generics.tax_provider.adapter')
return new Adapter(generic ? generic.config : this.app.config.get('generics.tax_provider.config'))
return new Adapter(this.app, generic ? generic.config : this.app.config.get('generics.tax_provider.config'))
}

/**
Expand Down
18 changes: 9 additions & 9 deletions lib/config/generics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@
export const generics = {
email_provider: {
adapter: null,
options: {}
config: {}
},
payment_processor: {
adapter: null,
options: {}
config: {}
},
tax_provider: {
adapter: null,
options: {}
config: {}
},
shipping_provider: {
adapter: null,
options: {}
config: {}
},
fulfillment_provider: {
adapter: null,
options: {}
config: {}
},
data_store_provider: {
adapter: null,
options: {}
config: {}
},
geolocation_provider: {
adapter: null,
options: {}
config: {}
},
image_provider: {
adapter: null,
options: {}
config: {}
},
render_service: {
adapter: null,
options: {}
config: {}
}
}
11 changes: 0 additions & 11 deletions lib/generics.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Errors from './errors'
import * as Schemas from './schemas'
export { Errors }
export { Validator} from './validator'
export { Generics } from './generics'
export { Utils } from './utils'
export { Generic } from './Generic'
export { GenericsSpool } from './GenericsSpool'
3 changes: 1 addition & 2 deletions lib/schemas/taxProvider/taxForOrder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import * as joi from 'joi'

// TODO schema
export const taxForOrder = joi.object().keys({
export const taxForOrder = joi.object().keys({
nexus_addresses: joi.array().items(
joi.object().keys({
product_ids: joi.array().items(joi.number()),
Expand Down
2 changes: 1 addition & 1 deletion lib/schemas/taxProvider/taxForOrderSuccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as joi from 'joi'

// TODO schema
export const taxForOrderSuccess = joi.object().keys({
export const taxForOrderSuccess = joi.object().keys({
total_taxes: joi.number(),
tax_lines: joi.array().items(
joi.object().keys({
Expand Down
31 changes: 20 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-generics",
"version": "1.1.0",
"version": "1.1.1",
"description": "Spool - Generic API",
"homepage": "https://fabrix.app",
"author": {
Expand Down Expand Up @@ -40,15 +40,15 @@
"joi": "^13.4.0"
},
"devDependencies": {
"@fabrix/fabrix": "^1.1.1",
"@fabrix/fabrix": "^1.1.3",
"@fabrix/lint": "^1.0.0-alpha.3",
"@fabrix/spool-router": "^1.1.2",
"@fabrix/spool-router": "^1.1.3",
"@types/lodash": "^4.14.109",
"@types/node": "~10.3.4",
"mocha": "^5",
"nyc": "^12.0.2",
"smokesignals": "^3",
"shortid": "^2.2.8",
"shortid": "^2.2.12",
"sqlite3": "^4.0.0",
"tslib": "~1.9.0",
"tslint": "~5.10.0",
Expand All @@ -57,8 +57,8 @@
"typescript": "~2.8.1"
},
"peerDependencies": {
"@fabrix/fabrix": "^1.1.1",
"@fabrix/spool-router": "^1.1.2"
"@fabrix/fabrix": "^1.1.3",
"@fabrix/spool-router": "^1.1.3"
},
"engines": {
"node": ">= 7.6.0"
Expand Down
7 changes: 2 additions & 5 deletions test/fixtures/FakeDataStore.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict'
const _ = require('lodash')
module.exports = class FakeDataStoreProvider {
constructor(config) {
this.config = config
}

const Generic = require('../../dist/Generic').Generic
module.exports = class FakeDataStoreProvider extends Generic {
upload(buffer) {
const res = {
status: 'success',
Expand Down
6 changes: 2 additions & 4 deletions test/fixtures/FakeEmail.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
// const _ = require('lodash')
module.exports = class FakeEmailProvider {
constructor(config) {
this.config = config
}
const Generic = require('../../dist/Generic').Generic
module.exports = class FakeEmailProvider extends Generic {
send(data) {
return Promise.resolve([])
}
Expand Down
6 changes: 2 additions & 4 deletions test/fixtures/FakeFulfillment.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
// const _ = require('lodash')
module.exports = class FakeFulfillmentProvider {
constructor(config) {
this.config = config
}
const Generic = require('../../dist/Generic').Generic
module.exports = class FakeFulfillmentProvider extends Generic {
createOrder(data, adapter){
return Promise.resolve({})
}
Expand Down
7 changes: 3 additions & 4 deletions test/fixtures/FakeGeneric.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'
// const _ = require('lodash')
module.exports = class FakeGeneric {
constructor(config) {
this.config = config
}
const Generic = require('../../dist/Generic').Generic
module.exports = class FakeGeneric extends Generic {

}
Loading

0 comments on commit 6bc8962

Please sign in to comment.