@authorizerdev/authorizer-js 0.1.0-beta.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -1
- package/lib/authorizer.min.js +15 -1
- package/lib/authorizer.min.js.map +1 -1
- package/lib/cjs/index.d.ts +88 -43
- package/lib/cjs/index.js +253 -186
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.d.ts +88 -43
- package/lib/esm/index.js +249 -184
- package/lib/esm/index.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +175 -74
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA+EA,IAAK,cAGJ;AAHD,WAAK,cAAc;IAClB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;AAClB,CAAC,EAHI,cAAc,KAAd,cAAc,QAGlB;AAED,MAAM,SAAS,GAAG,MAAe,OAAO,MAAM,KAAK,WAAW,CAAC;AAG/D,MAAM,iBAAiB,GAAG,qFAAqF,CAAC;MAE3F,UAAU;IAE9B,MAAM,CAAa;IAGnB,YAAY,MAAkB;QAC7B,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC7C;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;SACzC;QACD,IAAI,MAAM,CAAC,aAAa,EAAE;YACzB,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAChD,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACrD,IAAI,QAAQ,KAAK,GAAG,EAAE;gBACrB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"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js","../../../src/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || from);\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuDA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAChH,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,EAAE,UAAU,OAAO,EAAE,MAAM,EAAE;AAC/D,QAAQ,SAAS,SAAS,CAAC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CAAC,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;SAC1D;QACD,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE;YACtD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;SACvC;aAAM;YACN,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;SACtD;KACD;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1
|
|
2
|
+
"version": "0.2.1",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"typings": "lib/
|
|
4
|
+
"typings": "lib/cjs/index.d.ts",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
7
7
|
"files": [
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=10"
|
|
13
13
|
},
|
|
14
|
+
"repository": "https://github.com/authorizerdev/authorizer-js",
|
|
14
15
|
"scripts": {
|
|
15
16
|
"clean": "rm -rf lib",
|
|
16
17
|
"start": "rollup -w --config rollup.test.config.js",
|
package/src/index.ts
CHANGED
|
@@ -1,93 +1,146 @@
|
|
|
1
1
|
// Note: write gql query in single line to reduce bundle size
|
|
2
2
|
import nodeFetch from 'node-fetch';
|
|
3
3
|
|
|
4
|
-
type ConfigType = {
|
|
4
|
+
export type ConfigType = {
|
|
5
5
|
authorizerURL: string;
|
|
6
|
-
redirectURL
|
|
6
|
+
redirectURL: string;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
type User = {
|
|
9
|
+
export type User = {
|
|
10
10
|
id: string;
|
|
11
11
|
email: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
preferred_username: string;
|
|
13
|
+
email_verified: boolean;
|
|
14
|
+
signup_methods: string;
|
|
15
|
+
given_name?: string | null;
|
|
16
|
+
family_name?: string | null;
|
|
17
|
+
middle_name?: string | null;
|
|
18
|
+
picture?: string | null;
|
|
19
|
+
gender?: string | null;
|
|
20
|
+
birthdate?: string | null;
|
|
21
|
+
phone_number?: string | null;
|
|
22
|
+
phone_number_verified?: boolean | null;
|
|
23
|
+
roles?: string[];
|
|
24
|
+
created_at: number;
|
|
25
|
+
updated_at: number;
|
|
17
26
|
};
|
|
18
27
|
|
|
19
|
-
type AuthToken = {
|
|
28
|
+
export type AuthToken = {
|
|
20
29
|
message?: string;
|
|
21
|
-
|
|
22
|
-
|
|
30
|
+
access_token: string;
|
|
31
|
+
expires_at: number;
|
|
23
32
|
user?: User;
|
|
24
33
|
};
|
|
25
34
|
|
|
26
|
-
type Response = {
|
|
35
|
+
export type Response = {
|
|
27
36
|
message: string;
|
|
28
37
|
};
|
|
29
38
|
|
|
30
|
-
type Headers = Record<string, string>;
|
|
39
|
+
export type Headers = Record<string, string>;
|
|
31
40
|
|
|
32
|
-
type LoginInput = { email: string; password: string };
|
|
41
|
+
export type LoginInput = { email: string; password: string; roles?: string[] };
|
|
33
42
|
|
|
34
|
-
type SignupInput = {
|
|
43
|
+
export type SignupInput = {
|
|
35
44
|
email: string;
|
|
36
45
|
password: string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
confirm_password: string;
|
|
47
|
+
given_name?: string;
|
|
48
|
+
family_name?: string;
|
|
49
|
+
middle_name?: string;
|
|
50
|
+
picture?: string;
|
|
51
|
+
gender?: string;
|
|
52
|
+
birthdate?: string;
|
|
53
|
+
phone_number?: string;
|
|
54
|
+
roles?: string[];
|
|
40
55
|
};
|
|
41
56
|
|
|
42
|
-
type
|
|
57
|
+
export type MagicLinkLoginInput = {
|
|
58
|
+
email: string;
|
|
59
|
+
roles?: string[];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type VerifyEmailInput = { token: string };
|
|
43
63
|
|
|
44
|
-
type GraphqlQueryInput = {
|
|
64
|
+
export type GraphqlQueryInput = {
|
|
45
65
|
query: string;
|
|
46
66
|
variables?: Record<string, any>;
|
|
47
67
|
headers?: Headers;
|
|
48
68
|
};
|
|
49
69
|
|
|
50
|
-
type MetaData = {
|
|
70
|
+
export type MetaData = {
|
|
51
71
|
version: string;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
72
|
+
is_google_login_enabled: boolean;
|
|
73
|
+
is_facebook_login_enabled: boolean;
|
|
74
|
+
is_github_login_enabled: boolean;
|
|
75
|
+
is_email_verification_enabled: boolean;
|
|
76
|
+
is_basic_authentication_enabled: boolean;
|
|
77
|
+
is_magic_link_login_enabled: boolean;
|
|
58
78
|
};
|
|
59
79
|
|
|
60
|
-
type UpdateProfileInput = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
firstName?: string;
|
|
65
|
-
lastName?: string;
|
|
66
|
-
image?: string;
|
|
80
|
+
export type UpdateProfileInput = {
|
|
81
|
+
old_password?: string;
|
|
82
|
+
new_password?: string;
|
|
83
|
+
confirm_new_password?: string;
|
|
67
84
|
email?: string;
|
|
85
|
+
given_name?: string;
|
|
86
|
+
family_name?: string;
|
|
87
|
+
middle_name?: string;
|
|
88
|
+
nickname?: string;
|
|
89
|
+
gender?: string;
|
|
90
|
+
birthdate?: string;
|
|
91
|
+
phone_number?: string;
|
|
92
|
+
picture?: string;
|
|
68
93
|
};
|
|
69
94
|
|
|
70
|
-
type ForgotPasswordInput = {
|
|
95
|
+
export type ForgotPasswordInput = {
|
|
71
96
|
email: string;
|
|
72
97
|
};
|
|
73
98
|
|
|
74
|
-
type ResetPasswordInput = {
|
|
99
|
+
export type ResetPasswordInput = {
|
|
75
100
|
token: string;
|
|
76
101
|
password: string;
|
|
77
|
-
|
|
102
|
+
confirm_password: string;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type SessionQueryInput = {
|
|
106
|
+
roles?: string[];
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type IsValidJWTQueryInput = {
|
|
110
|
+
jwt: string;
|
|
111
|
+
roles?: string[];
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type ValidJWTResponse = {
|
|
115
|
+
valid: string;
|
|
116
|
+
message: string;
|
|
78
117
|
};
|
|
79
118
|
|
|
80
|
-
enum OAuthProviders {
|
|
119
|
+
export enum OAuthProviders {
|
|
81
120
|
Github = 'github',
|
|
82
121
|
Google = 'google',
|
|
122
|
+
Facebook = 'facebook',
|
|
83
123
|
}
|
|
84
124
|
|
|
85
125
|
const hasWindow = (): boolean => typeof window !== 'undefined';
|
|
86
126
|
|
|
87
127
|
// re-usable gql response fragment
|
|
88
|
-
const
|
|
128
|
+
const userFragment = `id email email_verified given_name family_name middle_name nickname preferred_username picture signup_methods gender birthdate phone_number phone_number_verified roles created_at updated_at `;
|
|
129
|
+
const authTokenFragment = `message access_token expires_at user { ${userFragment} }`;
|
|
130
|
+
|
|
131
|
+
const trimURL = (url: string): string => {
|
|
132
|
+
let trimmedData = url.trim();
|
|
133
|
+
const lastChar = trimmedData[trimmedData.length - 1];
|
|
134
|
+
if (lastChar === '/') {
|
|
135
|
+
trimmedData = trimmedData.slice(0, -1);
|
|
136
|
+
} else {
|
|
137
|
+
trimmedData = trimmedData;
|
|
138
|
+
}
|
|
89
139
|
|
|
90
|
-
|
|
140
|
+
return trimmedData;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export class Authorizer {
|
|
91
144
|
// class variable
|
|
92
145
|
config: ConfigType;
|
|
93
146
|
|
|
@@ -97,20 +150,16 @@ export default class Authorizer {
|
|
|
97
150
|
throw new Error(`Configuration is required`);
|
|
98
151
|
}
|
|
99
152
|
this.config = config;
|
|
100
|
-
if (!config.authorizerURL.trim()) {
|
|
153
|
+
if (!config.authorizerURL && !config.authorizerURL.trim()) {
|
|
101
154
|
throw new Error(`Invalid authorizerURL`);
|
|
102
155
|
}
|
|
103
156
|
if (config.authorizerURL) {
|
|
104
|
-
|
|
105
|
-
const lastChar = trimmedData[trimmedData.length - 1];
|
|
106
|
-
if (lastChar === '/') {
|
|
107
|
-
this.config.authorizerURL = trimmedData.slice(0, -1);
|
|
108
|
-
} else {
|
|
109
|
-
this.config.authorizerURL = trimmedData;
|
|
110
|
-
}
|
|
157
|
+
this.config.authorizerURL = trimURL(config.authorizerURL);
|
|
111
158
|
}
|
|
112
|
-
if (!config.redirectURL) {
|
|
159
|
+
if (!config.redirectURL && !config.redirectURL.trim()) {
|
|
113
160
|
throw new Error(`Invalid redirectURL`);
|
|
161
|
+
} else {
|
|
162
|
+
this.config.redirectURL = trimURL(config.redirectURL);
|
|
114
163
|
}
|
|
115
164
|
}
|
|
116
165
|
|
|
@@ -146,7 +195,7 @@ export default class Authorizer {
|
|
|
146
195
|
getMetaData = async (): Promise<MetaData | void> => {
|
|
147
196
|
try {
|
|
148
197
|
const res = await this.graphqlQuery({
|
|
149
|
-
query: `query { meta { version
|
|
198
|
+
query: `query { meta { version is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled } }`,
|
|
150
199
|
});
|
|
151
200
|
|
|
152
201
|
return res.meta;
|
|
@@ -156,13 +205,52 @@ export default class Authorizer {
|
|
|
156
205
|
};
|
|
157
206
|
|
|
158
207
|
// this is used to verify / get session using cookie by default. If using nodejs pass authorization header
|
|
159
|
-
getSession = async (
|
|
208
|
+
getSession = async (
|
|
209
|
+
headers?: Headers,
|
|
210
|
+
params?: SessionQueryInput,
|
|
211
|
+
): Promise<AuthToken> => {
|
|
160
212
|
try {
|
|
161
213
|
const res = await this.graphqlQuery({
|
|
162
|
-
query: `query {
|
|
214
|
+
query: `query getSession($params: SessionQueryInput){session(params: $params) { ${authTokenFragment} } }`,
|
|
163
215
|
headers,
|
|
216
|
+
variables: {
|
|
217
|
+
params,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
return res.session;
|
|
221
|
+
} catch (err) {
|
|
222
|
+
throw err;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
isValidJWT = async (data: {
|
|
227
|
+
jwt: string;
|
|
228
|
+
roles?: string[];
|
|
229
|
+
}): Promise<ValidJWTResponse> => {
|
|
230
|
+
try {
|
|
231
|
+
const res = await this.graphqlQuery({
|
|
232
|
+
query: `query isValidJWT($params: IsValidJWTQueryInput){ is_valid_jwt(params: $params) { message valid } }`,
|
|
233
|
+
variables: {
|
|
234
|
+
params: data,
|
|
235
|
+
},
|
|
164
236
|
});
|
|
165
|
-
|
|
237
|
+
|
|
238
|
+
return res.is_valid_jwt;
|
|
239
|
+
} catch (err) {
|
|
240
|
+
throw err;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
magicLinkLogin = async (data: MagicLinkLoginInput): Promise<Response> => {
|
|
245
|
+
try {
|
|
246
|
+
const res = await this.graphqlQuery({
|
|
247
|
+
query: `
|
|
248
|
+
mutation magicLinkLogin($data: MagicLinkLoginInput!) { magic_link_login(params: $data) { message }}
|
|
249
|
+
`,
|
|
250
|
+
variables: { data },
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return res.magic_link_login;
|
|
166
254
|
} catch (err) {
|
|
167
255
|
throw err;
|
|
168
256
|
}
|
|
@@ -172,13 +260,14 @@ export default class Authorizer {
|
|
|
172
260
|
try {
|
|
173
261
|
const res = await this.graphqlQuery({
|
|
174
262
|
query: `
|
|
175
|
-
|
|
263
|
+
mutation signup($data: SignUpInput!) { signup(params: $data) { ${authTokenFragment}}}
|
|
264
|
+
`,
|
|
176
265
|
variables: { data },
|
|
177
266
|
});
|
|
178
267
|
|
|
179
268
|
return res.signup;
|
|
180
269
|
} catch (err) {
|
|
181
|
-
|
|
270
|
+
throw err;
|
|
182
271
|
}
|
|
183
272
|
};
|
|
184
273
|
|
|
@@ -186,13 +275,14 @@ export default class Authorizer {
|
|
|
186
275
|
try {
|
|
187
276
|
const res = await this.graphqlQuery({
|
|
188
277
|
query: `
|
|
189
|
-
|
|
278
|
+
mutation verifyEmail($data: VerifyEmailInput!) { verify_email(params: $data) { ${authTokenFragment}}}
|
|
279
|
+
`,
|
|
190
280
|
variables: { data },
|
|
191
281
|
});
|
|
192
282
|
|
|
193
|
-
return res.
|
|
283
|
+
return res.verify_email;
|
|
194
284
|
} catch (err) {
|
|
195
|
-
|
|
285
|
+
throw err;
|
|
196
286
|
}
|
|
197
287
|
};
|
|
198
288
|
|
|
@@ -200,20 +290,21 @@ export default class Authorizer {
|
|
|
200
290
|
try {
|
|
201
291
|
const res = await this.graphqlQuery({
|
|
202
292
|
query: `
|
|
203
|
-
|
|
293
|
+
mutation login($data: LoginInput!) { login(params: $data) { ${authTokenFragment}}}
|
|
294
|
+
`,
|
|
204
295
|
variables: { data },
|
|
205
296
|
});
|
|
206
297
|
|
|
207
298
|
return res.login;
|
|
208
299
|
} catch (err) {
|
|
209
|
-
|
|
300
|
+
throw err;
|
|
210
301
|
}
|
|
211
302
|
};
|
|
212
303
|
|
|
213
304
|
getProfile = async (headers?: Headers): Promise<User | void> => {
|
|
214
305
|
try {
|
|
215
306
|
const profileRes = await this.graphqlQuery({
|
|
216
|
-
query: `query { profile {
|
|
307
|
+
query: `query { profile { ${userFragment} } }`,
|
|
217
308
|
headers,
|
|
218
309
|
});
|
|
219
310
|
|
|
@@ -229,14 +320,14 @@ export default class Authorizer {
|
|
|
229
320
|
): Promise<Response | void> => {
|
|
230
321
|
try {
|
|
231
322
|
const updateProfileRes = await this.graphqlQuery({
|
|
232
|
-
query: `mutation updateProfile($data: UpdateProfileInput!) {
|
|
323
|
+
query: `mutation updateProfile($data: UpdateProfileInput!) { update_profile(params: $data) { message } }`,
|
|
233
324
|
headers,
|
|
234
325
|
variables: {
|
|
235
326
|
data,
|
|
236
327
|
},
|
|
237
328
|
});
|
|
238
329
|
|
|
239
|
-
return updateProfileRes.
|
|
330
|
+
return updateProfileRes.update_profile;
|
|
240
331
|
} catch (error) {
|
|
241
332
|
throw error;
|
|
242
333
|
}
|
|
@@ -247,13 +338,13 @@ export default class Authorizer {
|
|
|
247
338
|
): Promise<Response | void> => {
|
|
248
339
|
try {
|
|
249
340
|
const forgotPasswordRes = await this.graphqlQuery({
|
|
250
|
-
query: `mutation forgotPassword($data: ForgotPasswordInput!) {
|
|
341
|
+
query: `mutation forgotPassword($data: ForgotPasswordInput!) { forgot_password(params: $data) { message } }`,
|
|
251
342
|
variables: {
|
|
252
343
|
data,
|
|
253
344
|
},
|
|
254
345
|
});
|
|
255
346
|
|
|
256
|
-
return forgotPasswordRes.
|
|
347
|
+
return forgotPasswordRes.forgot_password;
|
|
257
348
|
} catch (error) {
|
|
258
349
|
throw error;
|
|
259
350
|
}
|
|
@@ -264,32 +355,37 @@ export default class Authorizer {
|
|
|
264
355
|
): Promise<Response | void> => {
|
|
265
356
|
try {
|
|
266
357
|
const resetPasswordRes = await this.graphqlQuery({
|
|
267
|
-
query: `mutation resetPassword($data: ResetPasswordInput!) {
|
|
358
|
+
query: `mutation resetPassword($data: ResetPasswordInput!) { reset_password(params: $data) { message } }`,
|
|
268
359
|
variables: {
|
|
269
360
|
data,
|
|
270
361
|
},
|
|
271
362
|
});
|
|
272
|
-
return resetPasswordRes.
|
|
363
|
+
return resetPasswordRes.reset_password;
|
|
273
364
|
} catch (error) {
|
|
274
365
|
throw error;
|
|
275
366
|
}
|
|
276
367
|
};
|
|
277
368
|
|
|
278
|
-
|
|
369
|
+
browserLogin = async (): Promise<AuthToken | void> => {
|
|
279
370
|
try {
|
|
280
371
|
const token = await this.getSession();
|
|
281
372
|
return token;
|
|
282
373
|
} catch (err) {
|
|
283
374
|
if (!hasWindow()) {
|
|
284
|
-
throw new Error(`
|
|
375
|
+
throw new Error(`browserLogin is only supported for browsers`);
|
|
285
376
|
}
|
|
286
|
-
window.location.
|
|
287
|
-
|
|
288
|
-
|
|
377
|
+
window.location.replace(
|
|
378
|
+
`${this.config.authorizerURL}/app?state=${btoa(
|
|
379
|
+
JSON.stringify(this.config),
|
|
380
|
+
)}`,
|
|
381
|
+
);
|
|
289
382
|
}
|
|
290
383
|
};
|
|
291
384
|
|
|
292
|
-
oauthLogin = async (
|
|
385
|
+
oauthLogin = async (
|
|
386
|
+
oauthProvider: string,
|
|
387
|
+
roles?: string[],
|
|
388
|
+
): Promise<void> => {
|
|
293
389
|
// @ts-ignore
|
|
294
390
|
if (!Object.values(OAuthProviders).includes(oauthProvider)) {
|
|
295
391
|
throw new Error(
|
|
@@ -301,7 +397,11 @@ export default class Authorizer {
|
|
|
301
397
|
if (!hasWindow()) {
|
|
302
398
|
throw new Error(`oauthLogin is only supported for browsers`);
|
|
303
399
|
}
|
|
304
|
-
window.location.
|
|
400
|
+
window.location.replace(
|
|
401
|
+
`${this.config.authorizerURL}/oauth_login/${oauthProvider}?redirectURL=${
|
|
402
|
+
this.config.redirectURL || window.location.origin
|
|
403
|
+
}${roles && roles.length ? `&roles=${roles.join(',')}` : ``}`,
|
|
404
|
+
);
|
|
305
405
|
};
|
|
306
406
|
|
|
307
407
|
logout = async (headers?: Headers): Promise<Response | void> => {
|
|
@@ -312,6 +412,7 @@ export default class Authorizer {
|
|
|
312
412
|
});
|
|
313
413
|
return res.logout;
|
|
314
414
|
} catch (err) {
|
|
415
|
+
console.log(`logout err:`, err);
|
|
315
416
|
console.error(err);
|
|
316
417
|
}
|
|
317
418
|
};
|