UNPKG

@eastsideco/escshopify

Version:

WIP JS library for Shopify, containing a variety of useful functionality.

1,482 lines (1,481 loc) 171 kB
{ "type": "File", "start": 0, "end": 1308, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 58, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 1308, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 58, "column": 0 } }, "sourceType": "module", "body": [ { "type": "ImportDeclaration", "start": 0, "end": 26, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 7, "end": 12, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "local": { "type": "Identifier", "start": 7, "end": 12, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 }, "identifierName": "axios" }, "name": "axios" } } ], "source": { "type": "StringLiteral", "start": 18, "end": 25, "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 25 } }, "extra": { "rawValue": "axios", "raw": "'axios'" }, "value": "axios" }, "trailingComments": [ { "type": "CommentBlock", "value": "* API root URL ", "start": 28, "end": 47, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 19 } } } ] }, { "type": "VariableDeclaration", "start": 48, "end": 102, "loc": { "start": { "line": 4, "column": 0 }, "end": { "line": 4, "column": 54 } }, "declarations": [ { "type": "VariableDeclarator", "start": 54, "end": 101, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 53 } }, "id": { "type": "Identifier", "start": 54, "end": 62, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 14 }, "identifierName": "ROOT_URL" }, "name": "ROOT_URL", "leadingComments": null }, "init": { "type": "StringLiteral", "start": 65, "end": 101, "loc": { "start": { "line": 4, "column": 17 }, "end": { "line": 4, "column": 53 } }, "extra": { "rawValue": "https://geo.eastsideapps.io/api/v1", "raw": "'https://geo.eastsideapps.io/api/v1'" }, "value": "https://geo.eastsideapps.io/api/v1" }, "leadingComments": null } ], "kind": "const", "leadingComments": [ { "type": "CommentBlock", "value": "* API root URL ", "start": 28, "end": 47, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 19 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "* Path for geolcation ", "start": 103, "end": 129, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 26 } } } ] }, { "type": "VariableDeclaration", "start": 130, "end": 165, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 6, "column": 35 } }, "declarations": [ { "type": "VariableDeclarator", "start": 136, "end": 164, "loc": { "start": { "line": 6, "column": 6 }, "end": { "line": 6, "column": 34 } }, "id": { "type": "Identifier", "start": 136, "end": 146, "loc": { "start": { "line": 6, "column": 6 }, "end": { "line": 6, "column": 16 }, "identifierName": "PATH_GEOIP" }, "name": "PATH_GEOIP", "leadingComments": null }, "init": { "type": "StringLiteral", "start": 149, "end": 164, "loc": { "start": { "line": 6, "column": 19 }, "end": { "line": 6, "column": 34 } }, "extra": { "rawValue": "/info?ip={ip}", "raw": "'/info?ip={ip}'" }, "value": "/info?ip={ip}" }, "leadingComments": null } ], "kind": "const", "leadingComments": [ { "type": "CommentBlock", "value": "* Path for geolcation ", "start": 103, "end": 129, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 26 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "* Path for currency info ", "start": 166, "end": 195, "loc": { "start": { "line": 7, "column": 0 }, "end": { "line": 7, "column": 29 } } } ] }, { "type": "VariableDeclaration", "start": 196, "end": 230, "loc": { "start": { "line": 8, "column": 0 }, "end": { "line": 8, "column": 34 } }, "declarations": [ { "type": "VariableDeclarator", "start": 202, "end": 229, "loc": { "start": { "line": 8, "column": 6 }, "end": { "line": 8, "column": 33 } }, "id": { "type": "Identifier", "start": 202, "end": 215, "loc": { "start": { "line": 8, "column": 6 }, "end": { "line": 8, "column": 19 }, "identifierName": "PATH_CURRENCY" }, "name": "PATH_CURRENCY", "leadingComments": null }, "init": { "type": "StringLiteral", "start": 218, "end": 229, "loc": { "start": { "line": 8, "column": 22 }, "end": { "line": 8, "column": 33 } }, "extra": { "rawValue": "/currency", "raw": "'/currency'" }, "value": "/currency" }, "leadingComments": null } ], "kind": "const", "leadingComments": [ { "type": "CommentBlock", "value": "* Path for currency info ", "start": 166, "end": 195, "loc": { "start": { "line": 7, "column": 0 }, "end": { "line": 7, "column": 29 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Handles requests to the ESC Geoservice.\n ", "start": 233, "end": 283, "loc": { "start": { "line": 11, "column": 0 }, "end": { "line": 13, "column": 3 } } } ] }, { "type": "ExportDefaultDeclaration", "start": 284, "end": 1307, "loc": { "start": { "line": 14, "column": 0 }, "end": { "line": 57, "column": 1 } }, "declaration": { "type": "ClassDeclaration", "start": 299, "end": 1307, "loc": { "start": { "line": 14, "column": 15 }, "end": { "line": 57, "column": 1 } }, "id": { "type": "Identifier", "start": 305, "end": 308, "loc": { "start": { "line": 14, "column": 21 }, "end": { "line": 14, "column": 24 }, "identifierName": "API" }, "name": "API", "leadingComments": null }, "superClass": null, "body": { "type": "ClassBody", "start": 309, "end": 1307, "loc": { "start": { "line": 14, "column": 25 }, "end": { "line": 57, "column": 1 } }, "body": [ { "type": "ClassMethod", "start": 372, "end": 456, "loc": { "start": { "line": 18, "column": 4 }, "end": { "line": 21, "column": 5 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 372, "end": 383, "loc": { "start": { "line": 18, "column": 4 }, "end": { "line": 18, "column": 15 }, "identifierName": "constructor" }, "name": "constructor", "leadingComments": null }, "kind": "constructor", "id": null, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 386, "end": 456, "loc": { "start": { "line": 18, "column": 18 }, "end": { "line": 21, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 426, "end": 450, "loc": { "start": { "line": 20, "column": 8 }, "end": { "line": 20, "column": 32 } }, "expression": { "type": "AssignmentExpression", "start": 426, "end": 449, "loc": { "start": { "line": 20, "column": 8 }, "end": { "line": 20, "column": 31 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 426, "end": 438, "loc": { "start": { "line": 20, "column": 8 }, "end": { "line": 20, "column": 20 } }, "object": { "type": "ThisExpression", "start": 426, "end": 430, "loc": { "start": { "line": 20, "column": 8 }, "end": { "line": 20, "column": 12 } }, "leadingComments": null }, "property": { "type": "Identifier", "start": 431, "end": 438, "loc": { "start": { "line": 20, "column": 13 }, "end": { "line": 20, "column": 20 }, "identifierName": "rootUrl" }, "name": "rootUrl" }, "computed": false, "leadingComments": null }, "right": { "type": "Identifier", "start": 441, "end": 449, "loc": { "start": { "line": 20, "column": 23 }, "end": { "line": 20, "column": 31 }, "identifierName": "ROOT_URL" }, "name": "ROOT_URL" }, "leadingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "* @type {String} ", "start": 396, "end": 417, "loc": { "start": { "line": 19, "column": 8 }, "end": { "line": 19, "column": 29 } } } ] } ], "directives": [], "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Create a new instance of the API.\n ", "start": 315, "end": 367, "loc": { "start": { "line": 15, "column": 4 }, "end": { "line": 17, "column": 7 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Lookup GeoIP info for a given IP address. Uses local IP if not provided.\n * @param {String|null} ip\n * @returns {Promise<Object, Error>} GeoIP info. Throws if request fails.\n ", "start": 462, "end": 662, "loc": { "start": { "line": 23, "column": 4 }, "end": { "line": 27, "column": 7 } } } ] }, { "type": "ClassMethod", "start": 667, "end": 970, "loc": { "start": { "line": 28, "column": 4 }, "end": { "line": 40, "column": 5 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 673, "end": 678, "loc": { "start": { "line": 28, "column": 10 }, "end": { "line": 28, "column": 15 }, "identifierName": "geoip" }, "name": "geoip" }, "kind": "method", "id": null, "generator": false, "expression": false, "async": true, "params": [ { "type": "Identifier", "start": 679, "end": 681, "loc": { "start": { "line": 28, "column": 16 }, "end": { "line": 28, "column": 18 }, "identifierName": "ip" }, "name": "ip" } ], "body": { "type": "BlockStatement", "start": 683, "end": 970, "loc": { "start": { "line": 28, "column": 20 }, "end": { "line": 40, "column": 5 } }, "body": [ { "type": "IfStatement", "start": 693, "end": 734, "loc": { "start": { "line": 29, "column": 8 }, "end": { "line": 31, "column": 9 } }, "test": { "type": "UnaryExpression", "start": 697, "end": 700, "loc": { "start": { "line": 29, "column": 12 }, "end": { "line": 29, "column": 15 } }, "operator": "!", "prefix": true, "argument": { "type": "Identifier", "start": 698, "end": 700, "loc": { "start": { "line": 29, "column": 13 }, "end": { "line": 29, "column": 15 }, "identifierName": "ip" }, "name": "ip" }, "extra": { "parenthesizedArgument": false } }, "consequent": { "type": "BlockStatement", "start": 702, "end": 734, "loc": { "start": { "line": 29, "column": 17 }, "end": { "line": 31, "column": 9 } }, "body": [ { "type": "ExpressionStatement", "start": 716, "end": 724, "loc": { "start": { "line": 30, "column": 12 }, "end": { "line": 30, "column": 20 } }, "expression": { "type": "AssignmentExpression", "start": 716, "end": 723, "loc": { "start": { "line": 30, "column": 12 }, "end": { "line": 30, "column": 19 } }, "operator": "=", "left": { "type": "Identifier", "start": 716, "end": 718, "loc": { "start": { "line": 30, "column": 12 }, "end": { "line": 30, "column": 14 }, "identifierName": "ip" }, "name": "ip" }, "right": { "type": "StringLiteral", "start": 721, "end": 723, "loc": { "start": { "line": 30, "column": 17 }, "end": { "line": 30, "column": 19 } }, "extra": { "rawValue": "", "raw": "''" }, "value": "" } } } ], "directives": [] }, "alternate": null }, { "type": "VariableDeclaration", "start": 743, "end": 799, "loc": { "start": { "line": 32, "column": 8 }, "end": { "line": 32, "column": 64 } }, "declarations": [ { "type": "VariableDeclarator", "start": 747, "end": 798, "loc": { "start": { "line": 32, "column": 12 }, "end": { "line": 32, "column": 63 } }, "id": { "type": "Identifier", "start": 747, "end": 750, "loc": { "start": { "line": 32, "column": 12 }, "end": { "line": 32, "column": 15 }, "identifierName": "url" }, "name": "url" }, "init": { "type": "BinaryExpression", "start": 753, "end": 798, "loc": { "start": { "line": 32, "column": 18 }, "end": { "line": 32, "column": 63 } }, "left": { "type": "MemberExpression", "start": 753, "end": 765, "loc": { "start": { "line": 32, "column": 18 }, "end": { "line": 32, "column": 30 } }, "object": { "type": "ThisExpression", "start": 753, "end": 757, "loc": { "start": { "line": 32, "column": 18 }, "end": { "line": 32, "column": 22 } } }, "property": { "type": "Identifier", "start": 758, "end": 765, "loc": { "start": { "line": 32, "column": 23 }, "end": { "line": 32, "column": 30 }, "identifierName": "rootUrl" }, "name": "rootUrl" }, "computed": false }, "operator": "+", "right": { "type": "CallExpression", "start": 768, "end": 798, "loc": { "start": { "line": 32, "column": 33 }, "end": { "line": 32, "column": 63 } }, "callee": { "type": "MemberExpression", "start": 768, "end": 786, "loc": { "start": { "line": 32, "column": 33 }, "end": { "line": 32, "column": 51 } }, "object": { "type": "Identifier", "start": 768, "end": 778, "loc": { "start": { "line": 32, "column": 33 }, "end": { "line": 32, "column": 43 }, "identifierName": "PATH_GEOIP" }, "name": "PATH_GEOIP" }, "property": { "type": "Identifier", "start": 779, "end": 786, "loc": { "start": { "line": 32, "column": 44 }, "end": { "line": 32, "column": 51 }, "identifierName": "replace" }, "name": "replace" }, "computed": false }, "arguments": [ { "type": "StringLiteral", "start": 787, "end": 793, "loc": { "start": { "line": 32, "column": 52 }, "end": { "line": 32, "column": 58 } }, "extra": { "rawValue": "{ip}", "raw": "'{ip}'" }, "value": "{ip}" }, { "type": "Identifier", "start": 795, "end": 797, "loc": { "start": { "line": 32, "column": 60 }, "end": { "line": 32, "column": 62 }, "identifierName": "ip" }, "name": "ip" } ] } } } ], "kind": "var" }, { "type": "VariableDeclaration", "start": 808, "end": 839, "loc": { "start": { "line": 33, "column": 8 }, "end": { "line": 33, "column": 39 } }, "declarations": [ { "type": "VariableDeclarator", "start": 812, "end": 838, "loc": { "start": { "line": 33, "column": 12 }, "end": { "line": 33, "column": 38 } }, "id": { "type": "Identifier", "start": 812, "end": 815, "loc": { "start": { "line": 33, "column": 12 }, "end": { "line": 33, "column": 15 }, "identifierName": "res" }, "name": "res" }, "init": { "type": "AwaitExpression", "start": 818, "end": 838, "loc": { "start": { "line": 33, "column": 18 }, "end": { "line": 33, "column": 38 } }, "argument": { "type": "CallExpression", "start": 824, "end": 838, "loc": { "start": { "line": 33, "column": 24 }, "end": { "line": 33, "column": 38 } }, "callee": { "type": "MemberExpression", "start": 824, "end": 833, "loc": { "start": { "line": 33, "column": 24 }, "end": { "line": 33, "column": 33 } }, "object": { "type": "Identifier", "start": 824, "end": 829, "loc": { "start": { "line": 33, "column": 24 }, "end": { "line": 33, "column": 29 }, "identifierName": "axios" }, "name": "axios" }, "property": { "type": "Identifier", "start": 830, "end": 833, "loc": { "start": { "line": 33, "column": 30 }, "end": { "line": 33, "column": 33 }, "identifierName": "get" }, "name": "get" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 834, "end": 837, "loc": { "start": { "line": 33, "column": 34 }, "end": { "line": 33, "column": 37 }, "identifierName": "url" }, "name": "url" } ] } } } ], "kind": "var" }, { "type": "IfStatement", "start": 849, "end": 931, "loc": { "start": { "line": 35, "column": 8 }, "end": { "line": 37, "column": 9 } }, "test": { "type": "UnaryExpression", "start": 853, "end": 870, "loc": { "start": { "line": 35, "column": 12 }, "end": { "line": 35, "column": 29 } }, "operator": "!", "prefix": true, "argument": { "type": "MemberExpression", "start": 854, "end": 870, "loc": { "start": { "line": 35, "column": 13 }, "end": { "line": 35, "column": 29 } }, "object": { "type": "MemberExpression", "start": 854, "end": 862, "loc": { "start": { "line": 35, "column": 13 }, "end": { "line": 35, "column": 21 } }, "object": { "type": "Identifier", "start": 854, "end": 857, "loc": { "start": { "line": 35, "column": 13 }, "end": { "line": 35, "column": 16 }, "identifierName": "res" }, "name": "res" }, "property": { "type": "Identifier", "start": 858, "end": 862, "loc": { "start": { "line": 35, "column": 17 }, "end": { "line": 35, "column": 21 }, "identifierName": "data" }, "name": "data" }, "computed": false }, "property": { "type": "Identifier", "start": 863, "end": 870, "loc": { "start": { "line": 35, "column": 22 }, "end": { "line": 35, "column": 29 }, "identifierName": "success" }, "name": "success" }, "computed": false }, "extra": { "parenthesizedArgument": false } }, "consequent": { "type": "BlockStatement", "start": 872, "end": 931, "loc": { "start": { "line": 35, "column": 31 }, "end": { "line": 37, "column": 9 } }, "body": [ { "type": "ThrowStatement", "start": 886, "end": 921, "loc": { "start": { "line": 36, "column": 12 }, "end": { "line": 36, "column": 47 } }, "argument": { "type": "NewExpression", "start": 892, "end": 920, "loc": { "start": { "line": 36, "column": 18 }, "end": { "line": 36, "column": 46 } }, "callee": { "type": "Identifier", "start": 896, "end": 901, "loc": { "start": { "line": 36, "column": 22 }, "end": { "line": 36, "column": 27 }, "identifierName": "Error" }, "name": "Error" }, "arguments": [ { "type": "StringLiteral", "start": 902, "end": 919, "loc": { "start": { "line": 36, "column": 28 },