diff --git a/.env.sample b/.env.sample index aa409cd..a1aee67 100644 --- a/.env.sample +++ b/.env.sample @@ -2,3 +2,7 @@ DB_HOST= DB_USER= DB_NAME= DB_PASS= + +PW_SALTROUNDS= +COOKIE_SECRET= +EASYPOST_API_KEY= diff --git a/api/middleware/validators.js b/api/middleware/validators.js index d680a27..67851f7 100644 --- a/api/middleware/validators.js +++ b/api/middleware/validators.js @@ -33,6 +33,13 @@ validators.publishedBool = body('published').isBoolean() validators.isUUID = field => body(field).isString().isUUID() +validators.address = [ + body('street1').isString().isLength({min: 1}).withMessage('Street address is required'), + body('city').isString().isLength({min: 1}).withMessage('City is required'), + body('state').isString().isLength({min: 1}).withMessage('State is required'), + body('zip').isString().isLength({min: 1}).withMessage('Postal code is required') +] + validators.handleApiError = (req, res, next) => { const errors = validationResult(req) diff --git a/api/orders.js b/api/orders.js index eb531b2..83bd843 100644 --- a/api/orders.js +++ b/api/orders.js @@ -1,4 +1,5 @@ const router = module.exports = require('express-promise-router')() +const easypost = new (require('@easypost/api'))(process.env.EASYPOST_API_KEY); const parseJSON = require('body-parser').json() const db = require('../db') @@ -15,3 +16,39 @@ router.get('/current', async (req, res) => { const order = await db.order.findForCart(req.cart.uuid); res.json(order) }) + +router.post('/current/address', parseJSON, validate.address, validate.handleApiError, async (req, res) => { + const order = await db.order.findForCart(req.cart.uuid); + if(!order) throw new Error("Unable to find current order"); + + const {name, street1, street2, city, state, zip} = req.body; + + const epAddress = new easypost.Address({ + name, street1, street2, city, state, zip, + verify: ['delivery'] + }) + + await epAddress.save() + + const {success} = epAddress.verifications.delivery + if(!success){ + // TODO: Send back an error and ask them to double-check? + } + + const address = await db.address.create( + epAddress.name, + epAddress.company, + epAddress.street1, + epAddress.street2, + epAddress.city, + epAddress.state, + epAddress.zip, + epAddress.country, + epAddress.phone, + epAddress.id + ) + + const updatedOrder = await db.order.addAddress(order.uuid, address.uuid) + + res.json(updatedOrder) +}) diff --git a/components/form/form.js b/components/form/form.js index 8c93919..67c5aa2 100644 --- a/components/form/form.js +++ b/components/form/form.js @@ -137,7 +137,7 @@ export const FormController = function FormController({children, className, url, // Map children const _children = React.Children.map(children, child => { - if(child.type === Button && child.props.type.toLowerCase() === 'submit') + if(child.type === Button && child.props.type?.toLowerCase() === 'submit') return React.cloneElement(child, { // Allow enabled prop to disable, but not solely enable enabled: child.props.enabled !== false && !submitting && !Object.values(state.fields).some(field=>!field.isValid), diff --git a/db/index.js b/db/index.js index 52e0a94..faee43b 100644 --- a/db/index.js +++ b/db/index.js @@ -5,5 +5,6 @@ module.exports = { user: require('./models/user'), session: require('./models/session'), cart: require('./models/cart'), - order: require('./models/order') + order: require('./models/order'), + address: require('./models/address') } diff --git a/db/mappings/order.js b/db/mappings/order.js index 30ea6e5..b0d2bb5 100644 --- a/db/mappings/order.js +++ b/db/mappings/order.js @@ -6,7 +6,8 @@ module.exports = [{ 'start_time' ], associations: [ - {name: 'user', mapId: 'userMap', columnPrefix: 'user_'} + {name: 'user', mapId: 'userMap', columnPrefix: 'user_'}, + {name: 'address', mapId: 'addressMap', columnPrefix: 'address_'} ], collections: [ {name: 'transactions', mapId: 'transactionMap', columnPrefix: 'transaction_'} @@ -25,4 +26,19 @@ module.exports = [{ associations: [ {name: 'cart', mapId: 'cartMap', columnPrefix: 'cart_'} ] +},{ + mapId: 'addressMap', + idProperty: 'uuid', + properties: [ + 'name', + 'company', + 'street1', + 'street2', + 'city', + 'state', + 'zip', + 'country', + 'phone', + 'easypost_id' + ] }] diff --git a/db/models/address.js b/db/models/address.js new file mode 100644 index 0000000..a6c8835 --- /dev/null +++ b/db/models/address.js @@ -0,0 +1,20 @@ +const pg = require('../pg') +const joinjs = require('join-js').default; +const debug = require('debug')('sos:db:address') +const mappings = require('../mappings') + +const address = module.exports = {} + +address.create = async (name, company, street1, street2, city, state, zip, country, phone, easypost_id) => { + const query = { + text: 'select * from sos.create_address($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)', + values: [ + name, company, street1, street2, city, state, zip, country, phone, easypost_id + ] + } + + debug(query) + + const {rows} = await pg.query(query) + return joinjs.map(rows, mappings, 'addressMap', 'address_')[0] +} diff --git a/db/models/order.js b/db/models/order.js index a65d6a9..a1a0d36 100644 --- a/db/models/order.js +++ b/db/models/order.js @@ -28,3 +28,18 @@ order.findForCart = async function(cart_uuid) { const {rows} = await pg.query(query) return joinjs.map(rows, mappings, 'orderMap', 'order_')[0]; } + + +order.addAddress = async function (order_uuid, address_uuid){ + const query = { + text: 'select * from sos.add_address_to_order($1, $2)', + values: [order_uuid, address_uuid] + } + + debug(query) + + // TODO: Update shipping and tax + + const {rows} = await pg.query(query) + return joinjs.map(rows, mappings, 'orderMap', 'order_')[0]; +} diff --git a/db/sql/2-views.sql b/db/sql/2-views.sql index 1250283..e8c4463 100644 --- a/db/sql/2-views.sql +++ b/db/sql/2-views.sql @@ -78,8 +78,9 @@ create or replace view sos.v_cart_price as group by cart_uuid; --- TODO: add address, coupon, delivery +-- TODO: add coupon, delivery create or replace view sos.v_order as select * from sos."order" left join sos."transaction" on transaction_order_uuid = order_uuid + left join sos."address" on order_address_uuid = address_uuid left join sos.v_cart on cart_uuid = transaction_cart_uuid; diff --git a/db/sql/3-functions.sql b/db/sql/3-functions.sql index 73ac3d3..670f75a 100644 --- a/db/sql/3-functions.sql +++ b/db/sql/3-functions.sql @@ -494,3 +494,43 @@ begin return query select * from sos.v_order where order_uuid = _order_uuid; end; $function$; + +create or replace function sos.create_address(_order_uuid uuid, _name text, _company text, _street1 text, _street2 text, _city text, _state text, _zip text, _country text, _phone text, _easypost_id text) + returns setof sos.v_order + language plpgsql +as $function$ +declare + _address_uuid uuid; +begin + insert into sos."address" ( + address_name, + address_company, + address_street1, + address_street2, + address_city, + address_state, + address_zip, + address_country, + address_phone, + address_easypost_id + ) values ( + _name, + _company, + _street1, + _street2, + _city, + _state, + _zip, + _country, + _phone, + _easypost_id + ) returning address_uuid into _address_uuid; + + if _order_uuid is not null then + update sos."order" set + order_address_uuid = _address_uuid + where order_uuid = _order_uuid; + end if; + + return query select * from sos.v_order where address_uuid = _address_uuid; +end; $function$; diff --git a/db/sql/4-permissions.sql b/db/sql/4-permissions.sql index e78ce98..2507592 100644 --- a/db/sql/4-permissions.sql +++ b/db/sql/4-permissions.sql @@ -1,2 +1,3 @@ GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA sos TO sos; -GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA sos TO sos; \ No newline at end of file +GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA sos TO sos; +GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA sos TO sos; diff --git a/package-lock.json b/package-lock.json index 10da8aa..9a0c543 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1003,6 +1003,41 @@ "resolved": "https://registry.npmjs.org/@csstools/convert-colors/-/convert-colors-1.4.0.tgz", "integrity": "sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw==" }, + "@easypost/api": { + "version": "3.8.1", + "resolved": "https://registry.npmjs.org/@easypost/api/-/api-3.8.1.tgz", + "integrity": "sha512-F2J7/GhP6SdgVgF7pAAw2AnQ4nXo7zHVFWis7Bo7LL0fIgqydcB3S5TfgBEFlA5v5/K0yykPM+hPaVidmRJMcw==", + "requires": { + "core-js": "3.1.3", + "nodent-runtime": "3.2.1", + "proptypes": "1.1.0", + "regenerator-runtime": "0.13.2", + "source-map-support": "0.5.12", + "superagent": "5.0.6", + "yargs": "13.2.4" + }, + "dependencies": { + "core-js": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.1.3.tgz", + "integrity": "sha512-PWZ+ZfuaKf178BIAg+CRsljwjIMRV8MY00CbZczkR6Zk5LfkSkjGoaab3+bqRQWVITNZxQB7TFYz+CFcyuamvA==" + }, + "regenerator-runtime": { + "version": "0.13.2", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz", + "integrity": "sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA==" + }, + "source-map-support": { + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz", + "integrity": "sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==", + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } + } + }, "@material/animation": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@material/animation/-/animation-5.1.0.tgz", @@ -1633,6 +1668,11 @@ "resolved": "https://registry.npmjs.org/async-sema/-/async-sema-3.0.0.tgz", "integrity": "sha512-zyCMBDl4m71feawrxYcVbHxv/UUkqm4nKJiLu3+l9lfiQha6jQ/9dxhrXLnzzBXVFqCTDwiUkZOz9XFbdEGQsg==" }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -2398,6 +2438,33 @@ "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.2.0.tgz", "integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==" }, + "cliui": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", + "requires": { + "string-width": "^3.1.0", + "strip-ansi": "^5.2.0", + "wrap-ansi": "^5.1.0" + }, + "dependencies": { + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + } + } + }, "clone": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", @@ -2463,6 +2530,14 @@ "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=" }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", @@ -2637,6 +2712,11 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, + "cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==" + }, "cookies": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.8.0.tgz", @@ -2917,6 +2997,11 @@ } } }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + }, "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", @@ -3001,6 +3086,11 @@ "rimraf": "^2.2.8" } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, "delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", @@ -3135,6 +3225,11 @@ "minimalistic-crypto-utils": "^1.0.0" } }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==" + }, "emojis-list": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-2.1.0.tgz", @@ -3285,6 +3380,60 @@ "safe-buffer": "^5.1.1" } }, + "execa": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", + "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", + "requires": { + "cross-spawn": "^6.0.0", + "get-stream": "^4.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" + }, + "dependencies": { + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "requires": { + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" + }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "requires": { + "shebang-regex": "^1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "requires": { + "isexe": "^2.0.0" + } + } + } + }, "expand-brackets": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-2.1.4.tgz", @@ -3652,6 +3801,21 @@ "worker-rpc": "^0.1.0" } }, + "form-data": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, + "formidable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.2.tgz", + "integrity": "sha512-V8gLm+41I/8kguQ4/o1D3RIHRmhYFG4pnNyonvua+40rqcEmT4+V71yaZ3B457xbbgCsCfjSPi65u/W6vK1U5Q==" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -3744,6 +3908,19 @@ } } }, + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" + }, + "get-stream": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "requires": { + "pump": "^3.0.0" + } + }, "get-value": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", @@ -4074,6 +4251,11 @@ "loose-envify": "^1.0.0" } }, + "invert-kv": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", + "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==" + }, "ipaddr.js": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", @@ -4235,6 +4417,11 @@ "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -4358,6 +4545,14 @@ "shell-quote": "^1.6.1" } }, + "lcid": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", + "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", + "requires": { + "invert-kv": "^2.0.0" + } + }, "load-json-file": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", @@ -4489,6 +4684,14 @@ "resolved": "https://registry.npmjs.org/mamacro/-/mamacro-0.0.3.tgz", "integrity": "sha512-qMEwh+UujcQ+kbz3T6V+wAmO2U8veoq2w+3wY8MquqwVA3jChfwY+Tk52GZKDfACEPjuZ7r2oJLejwpt8jtwTA==" }, + "map-age-cleaner": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", + "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", + "requires": { + "p-defer": "^1.0.0" + } + }, "map-cache": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", @@ -4517,6 +4720,23 @@ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, + "mem": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", + "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", + "requires": { + "map-age-cleaner": "^0.1.1", + "mimic-fn": "^2.0.0", + "p-is-promise": "^2.0.0" + }, + "dependencies": { + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" + } + } + }, "memory-fs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", @@ -5043,6 +5263,11 @@ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" }, + "nice-try": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" + }, "node-abi": { "version": "2.15.0", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.15.0.tgz", @@ -5133,6 +5358,11 @@ } } }, + "nodent-runtime": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/nodent-runtime/-/nodent-runtime-3.2.1.tgz", + "integrity": "sha512-7Ws63oC+215smeKJQCxzrK21VFVlCFBkwl0MOObt0HOpVQXs3u483sAmtkF33nNqZ5rSOQjB76fgyPBmAUrtCA==" + }, "noop-logger": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz", @@ -5202,6 +5432,21 @@ "npm-normalize-package-bin": "^1.0.1" } }, + "npm-run-path": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", + "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", + "requires": { + "path-key": "^2.0.0" + }, + "dependencies": { + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" + } + } + }, "npmlog": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", @@ -5345,6 +5590,16 @@ "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" }, + "os-locale": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", + "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", + "requires": { + "execa": "^1.0.0", + "lcid": "^2.0.0", + "mem": "^4.0.0" + } + }, "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", @@ -5359,6 +5614,21 @@ "os-tmpdir": "^1.0.0" } }, + "p-defer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", + "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=" + }, + "p-finally": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", + "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" + }, + "p-is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", + "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==" + }, "p-limit": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", @@ -6248,6 +6518,11 @@ "reflect.ownkeys": "^0.2.0" } }, + "proptypes": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proptypes/-/proptypes-1.1.0.tgz", + "integrity": "sha1-eLOCilqmuxMIk54N48YETf1L0jk=" + }, "proxy-addr": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", @@ -6545,6 +6820,16 @@ "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=" }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + }, + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + }, "resize-observer-polyfill": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz", @@ -7303,6 +7588,11 @@ "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=" }, + "strip-eof": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" + }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -7349,6 +7639,45 @@ "resolved": "https://registry.npmjs.org/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz", "integrity": "sha512-nTbZoaqoBnmK+ptANthb10ZRZOGC+EmTLLUxeYIuHNkEKcmKgXX1XWKkUBT2Ac4es3NybooPe0SmvKdhKJZAuw==" }, + "superagent": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.0.6.tgz", + "integrity": "sha512-Rs1F18i4/o3C5N1kKAjWRS+uwQma3zz8J+hduC3E6CCE9LMF44ZPInBuvAibpgDoTtj42nkRNuasQ2r2JeMMIw==", + "requires": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.2", + "debug": "^4.1.1", + "form-data": "^2.3.3", + "formidable": "^1.2.1", + "methods": "^1.1.2", + "mime": "^2.4.3", + "qs": "^6.7.0", + "readable-stream": "^3.4.0", + "semver": "^6.1.1" + }, + "dependencies": { + "mime": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", + "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + } + } + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -8684,6 +9013,11 @@ "isexe": "^2.0.0" } }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" + }, "which-pm-runs": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz", @@ -8713,6 +9047,33 @@ "microevent.ts": "~0.1.1" } }, + "wrap-ansi": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "requires": { + "ansi-styles": "^3.2.0", + "string-width": "^3.0.0", + "strip-ansi": "^5.0.0" + }, + "dependencies": { + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + } + } + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -8743,6 +9104,88 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" + }, + "yargs": { + "version": "13.2.4", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.4.tgz", + "integrity": "sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg==", + "requires": { + "cliui": "^5.0.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", + "os-locale": "^3.1.0", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^13.1.0" + }, + "dependencies": { + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "requires": { + "locate-path": "^3.0.0" + } + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "requires": { + "p-limit": "^2.0.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + } + } + }, + "yargs-parser": { + "version": "13.1.2", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", + "integrity": "sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==", + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } } } } diff --git a/package.json b/package.json index 9ec195d..0a43cd5 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "license": "ISC", "devDependencies": {}, "dependencies": { + "@easypost/api": "^3.8.1", "@rmwc/button": "^6.0.14", "@rmwc/icon": "^6.0.12", "axios": "^0.19.2", diff --git a/pages/store/checkout/address.js b/pages/store/checkout/address.js index 4d76bbf..5b9dcf2 100644 --- a/pages/store/checkout/address.js +++ b/pages/store/checkout/address.js @@ -1,17 +1,28 @@ import {FormController, Input, Button} from '~/components/form' +import Router from 'next/router' + +InputAddress.getInitialProps = async function({ctx: {axios}}){ + const {data: {address}} = await axios.get(`/api/orders/current`) + return {address} +} + +export default function InputAddress({address}){ + const afterSave = () => { + Router.push('/store/checkout') + } -export default function InputAddress(){ return ( <>

Enter Address

- - - - - - - + + value.length > 0}/> + value.length > 0}/> + + value.length > 0}/> + value.length > 0}/> + value.length > 0}/> + ) -} \ No newline at end of file +} diff --git a/pages/store/checkout/index.js b/pages/store/checkout/index.js index 8a23490..c117bab 100644 --- a/pages/store/checkout/index.js +++ b/pages/store/checkout/index.js @@ -22,7 +22,7 @@ export default function CheckoutSummary({order}){ const {item_total_price, shipping_price, tax_price} = currentTransaction const shippingPrice = shipping_price ? '$' + (shipping_price / 100) : null - const total_price = + const total_price = (item_total_price && shipping_price && tax_price) ? '$' + (item_total_price + shippingPrice + tax_price - coupon_effective_discount) : null @@ -34,27 +34,41 @@ export default function CheckoutSummary({order}){

Address

{ - user - ?( -
-

- TODO: Load previous addresses -

-
- ):( -
-

- Log in to use your
saved addresses -

+ order.address + ? ( +
+

{order.address.name}

+

{order.address.street1}

+

{order.address.street2}

+

{order.address.city}, {order.address.state}, {order.address.zip}

+

(Edit Address)

) + : ( + user + ?( +
+

+ TODO: Load previous addresses +

+
+ ):( + <> +
+

+ Log in to use your
saved addresses +

+
+ + OR + +
+ +
+ + ) + ) } - - OR - -
- -