@qelos/web-sdk 3.1.30 → 3.2.8

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/dist/auth.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare function getCode(): string;
2
+ export declare function onReAuthorize(callback: any): void;
3
+ export declare function reAuthorize(): void;
4
+ export declare function unAuthorize(): Promise<void>;
5
+ export declare function authorize(): Promise<any>;
package/dist/auth.js ADDED
@@ -0,0 +1,51 @@
1
+ import { dispatch, on } from './qelos';
2
+ let subscribers;
3
+ let currentCode = (new URL(location.href)).searchParams.get('code') || 'default';
4
+ export function getCode() {
5
+ return currentCode;
6
+ }
7
+ export function onReAuthorize(callback) {
8
+ if (!subscribers) {
9
+ subscribers = new Set();
10
+ }
11
+ subscribers.add(callback);
12
+ }
13
+ export function reAuthorize() {
14
+ dispatch('reAuthorize', { returnUrl: location.href });
15
+ }
16
+ on('reAuthorize', async ({ code, token }) => {
17
+ currentCode = code;
18
+ const data = await callAuthorize({ returnUrl: location.href, token });
19
+ if (subscribers && subscribers.size) {
20
+ subscribers.forEach(cb => cb(data));
21
+ }
22
+ });
23
+ export async function unAuthorize() {
24
+ await fetch('/api/un-authorize', {
25
+ method: 'post',
26
+ headers: {
27
+ code: currentCode
28
+ },
29
+ });
30
+ }
31
+ export async function authorize() {
32
+ const returnUrl = location.href.replace(location.search, '');
33
+ const token = (new URL(location.href)).searchParams.get('token');
34
+ window.addEventListener('beforeunload', unAuthorize);
35
+ on('shutdown', unAuthorize);
36
+ return callAuthorize({ returnUrl, token });
37
+ }
38
+ async function callAuthorize({ returnUrl, token }) {
39
+ const res = await fetch('/api/authorize', {
40
+ method: 'post',
41
+ headers: {
42
+ 'content-type': 'application/json',
43
+ },
44
+ body: JSON.stringify({
45
+ returnUrl,
46
+ token
47
+ })
48
+ });
49
+ return res.json();
50
+ }
51
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.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C7B,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAEjE,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACrD,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAG5B,OAAO,aAAa,CAAC,EAAC,SAAS,EAAE,KAAK,EAAC,CAAC,CAAA;AAC1C,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,EAAC,SAAS,EAAE,KAAK,EAAC;IAC7C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,gBAAgB,EAAE;QACxC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,SAAS;YACT,KAAK;SACN,CAAC;KACH,CAAC,CAAA;IAEF,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
+ import { authorize, unAuthorize } from './auth';
1
2
  export declare const code: string;
2
- export declare function unAuthorize(): Promise<void>;
3
- export declare function authorize(): Promise<any>;
3
+ export { authorize, unAuthorize };
package/dist/index.js CHANGED
@@ -1,30 +1,6 @@
1
- import { on } from './qelos';
2
1
  import loadStyles from './shared-style';
3
- export const code = (new URL(location.href)).searchParams.get('code') || 'default';
4
- export async function unAuthorize() {
5
- await fetch('/api/un-authorize', {
6
- method: 'post',
7
- headers: {
8
- code
9
- },
10
- });
11
- }
12
- export async function authorize() {
13
- const returnUrl = location.href.replace(location.search, '');
14
- const token = (new URL(location.href)).searchParams.get('token');
15
- const res = await fetch('/api/authorize', {
16
- method: 'post',
17
- headers: {
18
- 'content-type': 'application/json',
19
- },
20
- body: JSON.stringify({
21
- returnUrl,
22
- token
23
- })
24
- });
25
- window.addEventListener('beforeunload', unAuthorize);
26
- on('shutdown', unAuthorize);
27
- return res.json();
28
- }
2
+ import { getCode, authorize, unAuthorize } from './auth';
3
+ export const code = getCode();
4
+ export { authorize, unAuthorize };
29
5
  loadStyles();
30
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,EAAE,EAAC,MAAM,SAAS,CAAC;AAC3B,OAAO,UAAU,MAAM,gBAAgB,CAAC;AAExC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;AAEnF,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,KAAK,CAAC,mBAAmB,EAAE;QAC/B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,IAAI;SACL;KACF,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAEjE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,gBAAgB,EAAE;QACxC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,SAAS;YACT,KAAK;SACN,CAAC;KACH,CAAC,CAAA;IAEF,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACrD,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC;AAED,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAC,MAAM,QAAQ,CAAC;AAEvD,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;AAE9B,OAAO,EACL,SAAS,EACT,WAAW,EACZ,CAAA;AAED,UAAU,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qelos/web-sdk",
3
- "version": "3.1.30",
3
+ "version": "3.2.8",
4
4
  "description": "Frontend Web SDK for Qelos API",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "access": "public"
14
14
  },
15
15
  "devDependencies": {
16
- "typescript": "^4.6.3"
16
+ "typescript": "^4.9.5"
17
17
  },
18
18
  "gitHead": "c4a69b318689cb5c7d35a05f057e0ed6c9676594"
19
19
  }
package/src/auth.ts ADDED
@@ -0,0 +1,65 @@
1
+ import {dispatch, on} from './qelos';
2
+
3
+ let subscribers;
4
+
5
+ let currentCode = (new URL(location.href)).searchParams.get('code') || 'default';
6
+
7
+ export function getCode() {
8
+ return currentCode;
9
+ }
10
+
11
+ export function onReAuthorize(callback) {
12
+ if (!subscribers) {
13
+ subscribers = new Set();
14
+ }
15
+ subscribers.add(callback);
16
+ }
17
+
18
+ export function reAuthorize() {
19
+ dispatch('reAuthorize', {returnUrl: location.href});
20
+ }
21
+
22
+
23
+ on('reAuthorize', async ({code, token}) => {
24
+ currentCode = code;
25
+ const data = await callAuthorize({returnUrl: location.href, token});
26
+ if (subscribers && subscribers.size) {
27
+ subscribers.forEach(cb => cb(data))
28
+ }
29
+ });
30
+
31
+
32
+ export async function unAuthorize() {
33
+ await fetch('/api/un-authorize', {
34
+ method: 'post',
35
+ headers: {
36
+ code: currentCode
37
+ },
38
+ })
39
+ }
40
+
41
+ export async function authorize() {
42
+ const returnUrl = location.href.replace(location.search, '');
43
+ const token = (new URL(location.href)).searchParams.get('token');
44
+
45
+ window.addEventListener('beforeunload', unAuthorize);
46
+ on('shutdown', unAuthorize);
47
+
48
+
49
+ return callAuthorize({returnUrl, token})
50
+ }
51
+
52
+ async function callAuthorize({returnUrl, token}) {
53
+ const res = await fetch('/api/authorize', {
54
+ method: 'post',
55
+ headers: {
56
+ 'content-type': 'application/json',
57
+ },
58
+ body: JSON.stringify({
59
+ returnUrl,
60
+ token
61
+ })
62
+ })
63
+
64
+ return res.json();
65
+ }
package/src/index.ts CHANGED
@@ -1,36 +1,11 @@
1
- import {on} from './qelos';
2
1
  import loadStyles from './shared-style';
2
+ import {getCode, authorize, unAuthorize} from './auth';
3
3
 
4
- export const code = (new URL(location.href)).searchParams.get('code') || 'default';
4
+ export const code = getCode();
5
5
 
6
- export async function unAuthorize() {
7
- await fetch('/api/un-authorize', {
8
- method: 'post',
9
- headers: {
10
- code
11
- },
12
- })
13
- }
14
-
15
- export async function authorize() {
16
- const returnUrl = location.href.replace(location.search, '');
17
- const token = (new URL(location.href)).searchParams.get('token');
18
-
19
- const res = await fetch('/api/authorize', {
20
- method: 'post',
21
- headers: {
22
- 'content-type': 'application/json',
23
- },
24
- body: JSON.stringify({
25
- returnUrl,
26
- token
27
- })
28
- })
29
-
30
- window.addEventListener('beforeunload', unAuthorize);
31
- on('shutdown', unAuthorize);
32
-
33
- return res.json();
6
+ export {
7
+ authorize,
8
+ unAuthorize
34
9
  }
35
10
 
36
11
  loadStyles();