@opencampus/ocid-connect-js 1.0.1 → 1.1.2
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 +186 -0
- package/dist/ocid-connect-js.js +263 -31
- package/dist/ocid-connect-js.js.map +1 -1
- package/lib/sdk/auth.js +24 -23
- package/lib/sdk/endpoints/buildAuthEndpointUrl.js +5 -0
- package/lib/sdk/lib/CookieStorageProvider.js +50 -0
- package/lib/sdk/lib/StorageManager.js +18 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
- [Setup](#setup)
|
|
5
5
|
- [React Integration](#react-integration)
|
|
6
|
+
- [Next.js 13+ Integration](#next-js-13+-integration)
|
|
6
7
|
- [Javascript Integration](#javascript-integration)
|
|
7
8
|
- [License](#license)
|
|
8
9
|
|
|
@@ -33,6 +34,7 @@ import { OCConnect } from '@opencampus/ocid-connect-js';
|
|
|
33
34
|
|
|
34
35
|
const opts = {
|
|
35
36
|
redirectUri: 'http://localhost:3001/redirect',
|
|
37
|
+
referralCode: 'PARTNER6'
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
return (
|
|
@@ -56,6 +58,7 @@ Opts Property
|
|
|
56
58
|
| Property | Description |
|
|
57
59
|
| --- | --- |
|
|
58
60
|
| redirectUri | URL to return after the login process is completed |
|
|
61
|
+
| referralCode | Unique identifiers assigned to partners for tracking during OCID account's registration. |
|
|
59
62
|
|
|
60
63
|
Setup LoginCallBack to handle flow's result
|
|
61
64
|
|
|
@@ -124,6 +127,188 @@ const UserTokenPage = (props) => {
|
|
|
124
127
|
};
|
|
125
128
|
```
|
|
126
129
|
|
|
130
|
+
## Next Js 13+ Integration
|
|
131
|
+
|
|
132
|
+
Install dependencies
|
|
133
|
+
```bash
|
|
134
|
+
npm install @opencampus/ocid-connect-js
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
or
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
yarn add @opencampus/ocid-connect-js
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 1. Create a wrapper component
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
components/OCConnectWrapper.jsx
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
'use client'
|
|
151
|
+
|
|
152
|
+
import { ReactNode } from 'react';
|
|
153
|
+
import { OCConnect, OCConnectProps } from '@opencampus/ocid-connect-js';
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
export default function OCConnectWrapper({ children, opts, sandboxMode }) {
|
|
158
|
+
return (
|
|
159
|
+
<OCConnect opts={opts} sandboxMode={sandboxMode}>
|
|
160
|
+
{children}
|
|
161
|
+
</OCConnect>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
### 2. Update the root layout
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
app/layout.jsx
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
import OCConnectWrapper from '../components/OCConnectWrapper';
|
|
175
|
+
|
|
176
|
+
export default function RootLayout({
|
|
177
|
+
children,
|
|
178
|
+
}) {
|
|
179
|
+
const opts = {
|
|
180
|
+
redirectUri: 'http://localhost:3000/redirect', // Adjust this URL
|
|
181
|
+
referralCode: 'PARTNER6', // Assign partner code
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<html lang="en">
|
|
186
|
+
<body>
|
|
187
|
+
<OCConnectWrapper opts={opts} sandboxMode={true}>
|
|
188
|
+
{children}
|
|
189
|
+
</OCConnectWrapper>
|
|
190
|
+
</body>
|
|
191
|
+
</html>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 3. Create a redirect page
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
app/redirect/page.jsx
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
'use client'
|
|
204
|
+
|
|
205
|
+
import { LoginCallBack } from '@opencampus/ocid-connect-js';
|
|
206
|
+
import { useRouter } from 'next/navigation';
|
|
207
|
+
|
|
208
|
+
export default function RedirectPage() {
|
|
209
|
+
const router = useRouter();
|
|
210
|
+
|
|
211
|
+
const loginSuccess = () => {
|
|
212
|
+
router.push('/'); // Redirect after successful login
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const loginError = (error) => {
|
|
216
|
+
console.error('Login error:', error);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
function CustomErrorComponent() {
|
|
220
|
+
const { authState } = useOCAuth();
|
|
221
|
+
return <div>Error Logging in: {authState.error?.message}</div>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function CustomLoadingComponent() {
|
|
225
|
+
return <div>Loading....</div>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<LoginCallBack
|
|
230
|
+
errorCallback={loginError}
|
|
231
|
+
successCallback={loginSuccess}
|
|
232
|
+
customErrorComponent={<CustomErrorComponent />}
|
|
233
|
+
customLoadingComponent={<CustomLoadingComponent />}
|
|
234
|
+
/>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
### 4. Create a LoginButton Component
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
components/LoginButton.jsx
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
```js
|
|
248
|
+
'use client'
|
|
249
|
+
|
|
250
|
+
import { useOCAuth } from '@opencampus/ocid-connect-js';
|
|
251
|
+
|
|
252
|
+
export default function LoginButton() {
|
|
253
|
+
const { ocAuth } = useOCAuth();
|
|
254
|
+
|
|
255
|
+
const handleLogin = async () => {
|
|
256
|
+
try {
|
|
257
|
+
await ocAuth.signInWithRedirect({ state: 'opencampus' });
|
|
258
|
+
} catch (error) {
|
|
259
|
+
console.error('Login error:', error);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
return <button onClick={handleLogin}>Login</button>;
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### 5. Use Components in Your Page
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
app/page.jsx
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
```js
|
|
274
|
+
|
|
275
|
+
'use client';
|
|
276
|
+
|
|
277
|
+
import { useEffect } from 'react';
|
|
278
|
+
import LoginButton from '../components/LoginButton';
|
|
279
|
+
import { useOCAuth } from '@opencampus/ocid-connect-js';
|
|
280
|
+
|
|
281
|
+
export default function Home() {
|
|
282
|
+
const { authState, ocAuth } = useOCAuth();
|
|
283
|
+
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
console.log(authState);
|
|
286
|
+
}, [authState]); // Now it will log whenever authState changes
|
|
287
|
+
|
|
288
|
+
if (authState.error) {
|
|
289
|
+
return <div>Error: {authState.error.message}</div>;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Add a loading state
|
|
293
|
+
if (authState.isLoading) {
|
|
294
|
+
return <div>Loading...</div>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<div>
|
|
299
|
+
<h1>Welcome to My App</h1>
|
|
300
|
+
{authState.isAuthenticated ? (
|
|
301
|
+
<p>You are logged in! {JSON.stringify(ocAuth.getAuthInfo())}</p>
|
|
302
|
+
|
|
303
|
+
) : (
|
|
304
|
+
<LoginButton />
|
|
305
|
+
)}
|
|
306
|
+
</div>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
|
|
127
312
|
|
|
128
313
|
## Javascript Integration
|
|
129
314
|
If React is not desirable front end framework, Our sdk could be used to integrate seamlessly with others.
|
|
@@ -167,6 +352,7 @@ The login flow adhere with PKCE standard. The following params will be prepared
|
|
|
167
352
|
| scope | only support 'openid' at the moment |
|
|
168
353
|
| code_challenge | adhere with PKCE standard |
|
|
169
354
|
| code_challenge_method | Only S256 is supported at the moment |
|
|
355
|
+
| ref | Unique identifiers assigned to partners for tracking during user registration |
|
|
170
356
|
|
|
171
357
|
Sample usage to handle login response
|
|
172
358
|
|
package/dist/ocid-connect-js.js
CHANGED
|
@@ -111,7 +111,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
111
111
|
|
|
112
112
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useOCAuth", function() { return _react__WEBPACK_IMPORTED_MODULE_0__["useOCAuth"]; });
|
|
113
113
|
|
|
114
|
-
/* harmony import */ var _sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
114
|
+
/* harmony import */ var _sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(27);
|
|
115
115
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TokenManager", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["TokenManager"]; });
|
|
116
116
|
|
|
117
117
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TransactionManager", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["TransactionManager"]; });
|
|
@@ -120,6 +120,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
120
120
|
|
|
121
121
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["LocalStorageManager"]; });
|
|
122
122
|
|
|
123
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["getStorageClass"]; });
|
|
124
|
+
|
|
123
125
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OCAuthCore", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["OCAuthCore"]; });
|
|
124
126
|
|
|
125
127
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OCAuthLive", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["OCAuthLive"]; });
|
|
@@ -503,7 +505,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
503
505
|
/* harmony import */ var _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21);
|
|
504
506
|
/* harmony import */ var _lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(22);
|
|
505
507
|
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(10);
|
|
506
|
-
/* harmony import */ var _endpoints__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(
|
|
508
|
+
/* harmony import */ var _endpoints__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(25);
|
|
507
509
|
/* harmony import */ var _utils_errors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(18);
|
|
508
510
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
509
511
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
@@ -539,24 +541,26 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
539
541
|
|
|
540
542
|
|
|
541
543
|
var OCAuthCore = /*#__PURE__*/function () {
|
|
542
|
-
function OCAuthCore(loginEndpoint, redirectUri, transactionManager, tokenManager) {
|
|
544
|
+
function OCAuthCore(loginEndpoint, redirectUri, transactionManager, tokenManager, referralCode) {
|
|
543
545
|
_classCallCheck(this, OCAuthCore);
|
|
544
546
|
_defineProperty(this, "tokenManager", void 0);
|
|
545
547
|
_defineProperty(this, "authInfoManager", void 0);
|
|
546
548
|
_defineProperty(this, "transactionManager", void 0);
|
|
547
549
|
_defineProperty(this, "redirectUri", void 0);
|
|
548
550
|
_defineProperty(this, "loginEndPoint", void 0);
|
|
551
|
+
_defineProperty(this, "referralCode", void 0);
|
|
549
552
|
this.transactionManager = transactionManager;
|
|
550
553
|
this.tokenManager = tokenManager;
|
|
551
554
|
this.authInfoManager = new _lib_AuthInfoManager__WEBPACK_IMPORTED_MODULE_0__["default"]();
|
|
552
555
|
this.loginEndPoint = loginEndpoint;
|
|
553
556
|
this.redirectUri = redirectUri;
|
|
557
|
+
this.referralCode = referralCode;
|
|
554
558
|
this.syncAuthInfo();
|
|
555
559
|
}
|
|
556
560
|
return _createClass(OCAuthCore, [{
|
|
557
561
|
key: "clearStorage",
|
|
558
562
|
value: function clearStorage() {
|
|
559
|
-
this.transactionManager.
|
|
563
|
+
this.transactionManager.clear();
|
|
560
564
|
this.tokenManager.clear();
|
|
561
565
|
}
|
|
562
566
|
}, {
|
|
@@ -577,9 +581,10 @@ var OCAuthCore = /*#__PURE__*/function () {
|
|
|
577
581
|
signinParams = _context.sent;
|
|
578
582
|
meta = Object(_utils__WEBPACK_IMPORTED_MODULE_4__["createPkceMeta"])(signinParams);
|
|
579
583
|
this.transactionManager.save(meta);
|
|
584
|
+
signinParams.referralCode = this.referralCode;
|
|
580
585
|
requestUrl = Object(_endpoints__WEBPACK_IMPORTED_MODULE_5__["buildAuthEndpointUrl"])(signinParams, this.loginEndPoint);
|
|
581
586
|
window.location.assign(requestUrl);
|
|
582
|
-
case
|
|
587
|
+
case 10:
|
|
583
588
|
case "end":
|
|
584
589
|
return _context.stop();
|
|
585
590
|
}
|
|
@@ -680,50 +685,48 @@ var OCAuthCore = /*#__PURE__*/function () {
|
|
|
680
685
|
}
|
|
681
686
|
}]);
|
|
682
687
|
}();
|
|
683
|
-
var OCAuthLS = /*#__PURE__*/function (_OCAuthCore2) {
|
|
684
|
-
function OCAuthLS(loginEndPoint, tokenEndpoint, redirectUri, publicKey) {
|
|
685
|
-
_classCallCheck(this, OCAuthLS);
|
|
686
|
-
var pkceTransactionManager = new _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__["default"](_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["LocalStorageManager"]);
|
|
687
|
-
var tokenManager = new _lib_TokenManager__WEBPACK_IMPORTED_MODULE_1__["default"](_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["LocalStorageManager"], tokenEndpoint, publicKey);
|
|
688
|
-
return _callSuper(this, OCAuthLS, [loginEndPoint, redirectUri, pkceTransactionManager, tokenManager]);
|
|
689
|
-
}
|
|
690
|
-
_inherits(OCAuthLS, _OCAuthCore2);
|
|
691
|
-
return _createClass(OCAuthLS);
|
|
692
|
-
}(OCAuthCore);
|
|
693
688
|
var LIVE_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBIDHtLbgVM76SXZ4iuIjuO+ERQPnVpJzagOsZdYxFG3ZJmvfdpr/Z29SLUbdZWafrOlAVlKe1Ovf/tcH671tTw==';
|
|
694
689
|
var SANDBOX_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/EymMLXd/MVYPK5r2xXQj91ZVvX3OQ+QagvR2N6lCvRVjnzmOtPRTf+u5g1RliWnmuxbV3gTm0/0VuV/40Salg==';
|
|
695
|
-
var OCAuthLive = /*#__PURE__*/function (
|
|
690
|
+
var OCAuthLive = /*#__PURE__*/function (_OCAuthCore2) {
|
|
696
691
|
function OCAuthLive() {
|
|
697
692
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
698
693
|
_classCallCheck(this, OCAuthLive);
|
|
699
694
|
var overrideTokenEndpoint = opts.tokenEndPoint,
|
|
700
695
|
overrideLoginEndpoint = opts.loginEndPoint,
|
|
701
696
|
overridePublicKey = opts.publicKey,
|
|
702
|
-
redirectUri = opts.redirectUri
|
|
697
|
+
redirectUri = opts.redirectUri,
|
|
698
|
+
referralCode = opts.referralCode;
|
|
703
699
|
var tokenEndpoint = overrideTokenEndpoint || 'https://api.login.opencampus.xyz/auth/token';
|
|
704
700
|
var loginEndpoint = overrideLoginEndpoint || 'https://api.login.opencampus.xyz/auth/login';
|
|
705
701
|
var publicKey = overridePublicKey || LIVE_PUBLIC_KEY;
|
|
706
|
-
|
|
702
|
+
var storageClass = Object(_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["getStorageClass"])(opts);
|
|
703
|
+
var pkceTransactionManager = new _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__["default"](storageClass);
|
|
704
|
+
var tokenManager = new _lib_TokenManager__WEBPACK_IMPORTED_MODULE_1__["default"](storageClass, tokenEndpoint, publicKey);
|
|
705
|
+
return _callSuper(this, OCAuthLive, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager, referralCode]);
|
|
707
706
|
}
|
|
708
|
-
_inherits(OCAuthLive,
|
|
707
|
+
_inherits(OCAuthLive, _OCAuthCore2);
|
|
709
708
|
return _createClass(OCAuthLive);
|
|
710
|
-
}(
|
|
711
|
-
var OCAuthSandbox = /*#__PURE__*/function (
|
|
709
|
+
}(OCAuthCore);
|
|
710
|
+
var OCAuthSandbox = /*#__PURE__*/function (_OCAuthCore3) {
|
|
712
711
|
function OCAuthSandbox() {
|
|
713
712
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
714
713
|
_classCallCheck(this, OCAuthSandbox);
|
|
715
714
|
var overrideTokenEndpoint = opts.tokenEndPoint,
|
|
716
715
|
overrideLoginEndpoint = opts.loginEndPoint,
|
|
717
716
|
overridePublicKey = opts.publicKey,
|
|
718
|
-
redirectUri = opts.redirectUri
|
|
717
|
+
redirectUri = opts.redirectUri,
|
|
718
|
+
referralCode = opts.referralCode;
|
|
719
719
|
var tokenEndpoint = overrideTokenEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/token';
|
|
720
720
|
var loginEndpoint = overrideLoginEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/login';
|
|
721
721
|
var publicKey = overridePublicKey || SANDBOX_PUBLIC_KEY;
|
|
722
|
-
|
|
722
|
+
var storageClass = Object(_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["getStorageClass"])(opts);
|
|
723
|
+
var pkceTransactionManager = new _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__["default"](storageClass);
|
|
724
|
+
var tokenManager = new _lib_TokenManager__WEBPACK_IMPORTED_MODULE_1__["default"](storageClass, tokenEndpoint, publicKey);
|
|
725
|
+
return _callSuper(this, OCAuthSandbox, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager, referralCode]);
|
|
723
726
|
}
|
|
724
|
-
_inherits(OCAuthSandbox,
|
|
727
|
+
_inherits(OCAuthSandbox, _OCAuthCore3);
|
|
725
728
|
return _createClass(OCAuthSandbox);
|
|
726
|
-
}(
|
|
729
|
+
}(OCAuthCore);
|
|
727
730
|
|
|
728
731
|
/***/ }),
|
|
729
732
|
/* 8 */
|
|
@@ -1515,7 +1518,9 @@ var TransactionManager = /*#__PURE__*/function () {
|
|
|
1515
1518
|
__webpack_require__.r(__webpack_exports__);
|
|
1516
1519
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BaseStorageManager", function() { return BaseStorageManager; });
|
|
1517
1520
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return LocalStorageManager; });
|
|
1521
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return getStorageClass; });
|
|
1518
1522
|
/* harmony import */ var _utils_errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
|
|
1523
|
+
/* harmony import */ var _CookieStorageProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(23);
|
|
1519
1524
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
1520
1525
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1521
1526
|
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
@@ -1542,7 +1547,6 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
1542
1547
|
|
|
1543
1548
|
|
|
1544
1549
|
|
|
1545
|
-
// We only support local storage for now
|
|
1546
1550
|
var SavedObject = /*#__PURE__*/function () {
|
|
1547
1551
|
function SavedObject(storageProvider, storageName) {
|
|
1548
1552
|
_classCallCheck(this, SavedObject);
|
|
@@ -1631,6 +1635,21 @@ var LocalStorageManager = /*#__PURE__*/function (_BaseStorageManager2) {
|
|
|
1631
1635
|
_inherits(LocalStorageManager, _BaseStorageManager2);
|
|
1632
1636
|
return _createClass(LocalStorageManager);
|
|
1633
1637
|
}(BaseStorageManager);
|
|
1638
|
+
var getStorageClass = function getStorageClass(opts) {
|
|
1639
|
+
// Only cookie support domain based storage
|
|
1640
|
+
if (opts.storageType === 'cookie') {
|
|
1641
|
+
return /*#__PURE__*/function (_BaseStorageManager3) {
|
|
1642
|
+
function CookieStorageManager(storageName) {
|
|
1643
|
+
_classCallCheck(this, CookieStorageManager);
|
|
1644
|
+
return _callSuper(this, CookieStorageManager, [storageName, new _CookieStorageProvider__WEBPACK_IMPORTED_MODULE_1__["CookieStorageProvider"](opts.cookieDomain)]);
|
|
1645
|
+
}
|
|
1646
|
+
_inherits(CookieStorageManager, _BaseStorageManager3);
|
|
1647
|
+
return _createClass(CookieStorageManager);
|
|
1648
|
+
}(BaseStorageManager);
|
|
1649
|
+
} else {
|
|
1650
|
+
return LocalStorageManager;
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1634
1653
|
|
|
1635
1654
|
/***/ }),
|
|
1636
1655
|
/* 23 */
|
|
@@ -1638,7 +1657,211 @@ var LocalStorageManager = /*#__PURE__*/function (_BaseStorageManager2) {
|
|
|
1638
1657
|
|
|
1639
1658
|
"use strict";
|
|
1640
1659
|
__webpack_require__.r(__webpack_exports__);
|
|
1641
|
-
/* harmony
|
|
1660
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CookieStorageProvider", function() { return CookieStorageProvider; });
|
|
1661
|
+
/* harmony import */ var js_cookie__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(24);
|
|
1662
|
+
/* harmony import */ var js_cookie__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(js_cookie__WEBPACK_IMPORTED_MODULE_0__);
|
|
1663
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
1664
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
1665
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
1666
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
1667
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
1668
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
1669
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1670
|
+
/*!
|
|
1671
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
1672
|
+
*
|
|
1673
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
1674
|
+
*
|
|
1675
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
1676
|
+
*
|
|
1677
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1678
|
+
*/
|
|
1679
|
+
|
|
1680
|
+
|
|
1681
|
+
|
|
1682
|
+
// Wrapper to support Cookie based storage
|
|
1683
|
+
var CookieStorageProvider = /*#__PURE__*/function () {
|
|
1684
|
+
function CookieStorageProvider(domain) {
|
|
1685
|
+
_classCallCheck(this, CookieStorageProvider);
|
|
1686
|
+
_defineProperty(this, "domain", void 0);
|
|
1687
|
+
this.domain = domain;
|
|
1688
|
+
}
|
|
1689
|
+
return _createClass(CookieStorageProvider, [{
|
|
1690
|
+
key: "getItem",
|
|
1691
|
+
value: function getItem(key) {
|
|
1692
|
+
return js_cookie__WEBPACK_IMPORTED_MODULE_0___default.a.get(key);
|
|
1693
|
+
}
|
|
1694
|
+
}, {
|
|
1695
|
+
key: "setItem",
|
|
1696
|
+
value: function setItem(key, value) {
|
|
1697
|
+
return js_cookie__WEBPACK_IMPORTED_MODULE_0___default.a.set(key, value, {
|
|
1698
|
+
expires: 365,
|
|
1699
|
+
domain: this.domain
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
}, {
|
|
1703
|
+
key: "removeItem",
|
|
1704
|
+
value: function removeItem(key) {
|
|
1705
|
+
return js_cookie__WEBPACK_IMPORTED_MODULE_0___default.a.remove(key);
|
|
1706
|
+
}
|
|
1707
|
+
}]);
|
|
1708
|
+
}();
|
|
1709
|
+
|
|
1710
|
+
/***/ }),
|
|
1711
|
+
/* 24 */
|
|
1712
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1713
|
+
|
|
1714
|
+
/*! js-cookie v3.0.5 | MIT */
|
|
1715
|
+
;
|
|
1716
|
+
(function (global, factory) {
|
|
1717
|
+
true ? module.exports = factory() :
|
|
1718
|
+
undefined;
|
|
1719
|
+
})(this, (function () { 'use strict';
|
|
1720
|
+
|
|
1721
|
+
/* eslint-disable no-var */
|
|
1722
|
+
function assign (target) {
|
|
1723
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1724
|
+
var source = arguments[i];
|
|
1725
|
+
for (var key in source) {
|
|
1726
|
+
target[key] = source[key];
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
return target
|
|
1730
|
+
}
|
|
1731
|
+
/* eslint-enable no-var */
|
|
1732
|
+
|
|
1733
|
+
/* eslint-disable no-var */
|
|
1734
|
+
var defaultConverter = {
|
|
1735
|
+
read: function (value) {
|
|
1736
|
+
if (value[0] === '"') {
|
|
1737
|
+
value = value.slice(1, -1);
|
|
1738
|
+
}
|
|
1739
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
|
|
1740
|
+
},
|
|
1741
|
+
write: function (value) {
|
|
1742
|
+
return encodeURIComponent(value).replace(
|
|
1743
|
+
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
1744
|
+
decodeURIComponent
|
|
1745
|
+
)
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
/* eslint-enable no-var */
|
|
1749
|
+
|
|
1750
|
+
/* eslint-disable no-var */
|
|
1751
|
+
|
|
1752
|
+
function init (converter, defaultAttributes) {
|
|
1753
|
+
function set (name, value, attributes) {
|
|
1754
|
+
if (typeof document === 'undefined') {
|
|
1755
|
+
return
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
attributes = assign({}, defaultAttributes, attributes);
|
|
1759
|
+
|
|
1760
|
+
if (typeof attributes.expires === 'number') {
|
|
1761
|
+
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
1762
|
+
}
|
|
1763
|
+
if (attributes.expires) {
|
|
1764
|
+
attributes.expires = attributes.expires.toUTCString();
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
name = encodeURIComponent(name)
|
|
1768
|
+
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
1769
|
+
.replace(/[()]/g, escape);
|
|
1770
|
+
|
|
1771
|
+
var stringifiedAttributes = '';
|
|
1772
|
+
for (var attributeName in attributes) {
|
|
1773
|
+
if (!attributes[attributeName]) {
|
|
1774
|
+
continue
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
1778
|
+
|
|
1779
|
+
if (attributes[attributeName] === true) {
|
|
1780
|
+
continue
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// Considers RFC 6265 section 5.2:
|
|
1784
|
+
// ...
|
|
1785
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
1786
|
+
// character:
|
|
1787
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
1788
|
+
// not including, the first %x3B (";") character.
|
|
1789
|
+
// ...
|
|
1790
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
return (document.cookie =
|
|
1794
|
+
name + '=' + converter.write(value, name) + stringifiedAttributes)
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
function get (name) {
|
|
1798
|
+
if (typeof document === 'undefined' || (arguments.length && !name)) {
|
|
1799
|
+
return
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
// To prevent the for loop in the first place assign an empty array
|
|
1803
|
+
// in case there are no cookies at all.
|
|
1804
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
1805
|
+
var jar = {};
|
|
1806
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
1807
|
+
var parts = cookies[i].split('=');
|
|
1808
|
+
var value = parts.slice(1).join('=');
|
|
1809
|
+
|
|
1810
|
+
try {
|
|
1811
|
+
var found = decodeURIComponent(parts[0]);
|
|
1812
|
+
jar[found] = converter.read(value, found);
|
|
1813
|
+
|
|
1814
|
+
if (name === found) {
|
|
1815
|
+
break
|
|
1816
|
+
}
|
|
1817
|
+
} catch (e) {}
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
return name ? jar[name] : jar
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
return Object.create(
|
|
1824
|
+
{
|
|
1825
|
+
set,
|
|
1826
|
+
get,
|
|
1827
|
+
remove: function (name, attributes) {
|
|
1828
|
+
set(
|
|
1829
|
+
name,
|
|
1830
|
+
'',
|
|
1831
|
+
assign({}, attributes, {
|
|
1832
|
+
expires: -1
|
|
1833
|
+
})
|
|
1834
|
+
);
|
|
1835
|
+
},
|
|
1836
|
+
withAttributes: function (attributes) {
|
|
1837
|
+
return init(this.converter, assign({}, this.attributes, attributes))
|
|
1838
|
+
},
|
|
1839
|
+
withConverter: function (converter) {
|
|
1840
|
+
return init(assign({}, this.converter, converter), this.attributes)
|
|
1841
|
+
}
|
|
1842
|
+
},
|
|
1843
|
+
{
|
|
1844
|
+
attributes: { value: Object.freeze(defaultAttributes) },
|
|
1845
|
+
converter: { value: Object.freeze(converter) }
|
|
1846
|
+
}
|
|
1847
|
+
)
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
var api = init(defaultConverter, { path: '/' });
|
|
1851
|
+
/* eslint-enable no-var */
|
|
1852
|
+
|
|
1853
|
+
return api;
|
|
1854
|
+
|
|
1855
|
+
}));
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
/***/ }),
|
|
1859
|
+
/* 25 */
|
|
1860
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1861
|
+
|
|
1862
|
+
"use strict";
|
|
1863
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1864
|
+
/* harmony import */ var _buildAuthEndpointUrl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26);
|
|
1642
1865
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "buildAuthEndpointUrl", function() { return _buildAuthEndpointUrl__WEBPACK_IMPORTED_MODULE_0__["buildAuthEndpointUrl"]; });
|
|
1643
1866
|
|
|
1644
1867
|
/*!
|
|
@@ -1653,7 +1876,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1653
1876
|
|
|
1654
1877
|
|
|
1655
1878
|
/***/ }),
|
|
1656
|
-
/*
|
|
1879
|
+
/* 26 */
|
|
1657
1880
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1658
1881
|
|
|
1659
1882
|
"use strict";
|
|
@@ -1683,16 +1906,21 @@ var buildAuthEndpointUrl = function buildAuthEndpointUrl(signInParams, loginEndP
|
|
|
1683
1906
|
if (signInParams.state !== undefined) {
|
|
1684
1907
|
loginUrl.searchParams.append('state', signInParams.state);
|
|
1685
1908
|
}
|
|
1909
|
+
|
|
1910
|
+
// reference data for register workflow
|
|
1911
|
+
if (signInParams.referralCode) {
|
|
1912
|
+
loginUrl.searchParams.append('ref', signInParams.referralCode);
|
|
1913
|
+
}
|
|
1686
1914
|
return loginUrl.href;
|
|
1687
1915
|
};
|
|
1688
1916
|
|
|
1689
1917
|
/***/ }),
|
|
1690
|
-
/*
|
|
1918
|
+
/* 27 */
|
|
1691
1919
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1692
1920
|
|
|
1693
1921
|
"use strict";
|
|
1694
1922
|
__webpack_require__.r(__webpack_exports__);
|
|
1695
|
-
/* harmony import */ var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
1923
|
+
/* harmony import */ var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(28);
|
|
1696
1924
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TokenManager", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["TokenManager"]; });
|
|
1697
1925
|
|
|
1698
1926
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TransactionManager", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["TransactionManager"]; });
|
|
@@ -1701,6 +1929,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1701
1929
|
|
|
1702
1930
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["LocalStorageManager"]; });
|
|
1703
1931
|
|
|
1932
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["getStorageClass"]; });
|
|
1933
|
+
|
|
1704
1934
|
/* harmony import */ var _auth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
|
|
1705
1935
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OCAuthCore", function() { return _auth__WEBPACK_IMPORTED_MODULE_1__["OCAuthCore"]; });
|
|
1706
1936
|
|
|
@@ -1712,7 +1942,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1712
1942
|
|
|
1713
1943
|
|
|
1714
1944
|
/***/ }),
|
|
1715
|
-
/*
|
|
1945
|
+
/* 28 */
|
|
1716
1946
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1717
1947
|
|
|
1718
1948
|
"use strict";
|
|
@@ -1728,6 +1958,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1728
1958
|
|
|
1729
1959
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return _StorageManager__WEBPACK_IMPORTED_MODULE_2__["LocalStorageManager"]; });
|
|
1730
1960
|
|
|
1961
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return _StorageManager__WEBPACK_IMPORTED_MODULE_2__["getStorageClass"]; });
|
|
1962
|
+
|
|
1731
1963
|
|
|
1732
1964
|
|
|
1733
1965
|
|