login-authorization-v2 2.0.0-beta.1 → 2.0.0-beta.11

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.
Files changed (81) hide show
  1. package/README.md +45 -47
  2. package/dist/index.d.ts +14 -4
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.esm.js +413 -497
  5. package/dist/index.umd.js +432 -537
  6. package/dist/src/compatible.d.ts +1 -1
  7. package/dist/src/compatible.d.ts.map +1 -1
  8. package/dist/src/cookie.d.ts +2 -2
  9. package/dist/src/cookie.d.ts.map +1 -1
  10. package/dist/src/request.d.ts.map +1 -1
  11. package/package.json +29 -25
  12. package/babel.config.js +0 -6
  13. package/coverage/clover.xml +0 -140
  14. package/coverage/coverage-final.json +0 -8
  15. package/coverage/lcov-report/base.css +0 -224
  16. package/coverage/lcov-report/block-navigation.js +0 -87
  17. package/coverage/lcov-report/common-authorization-v2/index.html +0 -116
  18. package/coverage/lcov-report/common-authorization-v2/index.ts.html +0 -547
  19. package/coverage/lcov-report/common-authorization-v2/src/compatible.ts.html +0 -223
  20. package/coverage/lcov-report/common-authorization-v2/src/constance.ts.html +0 -106
  21. package/coverage/lcov-report/common-authorization-v2/src/cookie.ts.html +0 -346
  22. package/coverage/lcov-report/common-authorization-v2/src/dom.ts.html +0 -262
  23. package/coverage/lcov-report/common-authorization-v2/src/index.html +0 -206
  24. package/coverage/lcov-report/common-authorization-v2/src/request.ts.html +0 -361
  25. package/coverage/lcov-report/common-authorization-v2/src/shares.ts.html +0 -163
  26. package/coverage/lcov-report/common-authorization-v2/src/types.ts.html +0 -412
  27. package/coverage/lcov-report/common-authorization-v2/src/utils.ts.html +0 -145
  28. package/coverage/lcov-report/compatible.ts.html +0 -223
  29. package/coverage/lcov-report/constance.ts.html +0 -106
  30. package/coverage/lcov-report/cookie.ts.html +0 -310
  31. package/coverage/lcov-report/dom.ts.html +0 -262
  32. package/coverage/lcov-report/favicon.png +0 -0
  33. package/coverage/lcov-report/index.html +0 -206
  34. package/coverage/lcov-report/prettify.css +0 -1
  35. package/coverage/lcov-report/prettify.js +0 -2
  36. package/coverage/lcov-report/shares.ts.html +0 -163
  37. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  38. package/coverage/lcov-report/sorter.js +0 -210
  39. package/coverage/lcov-report/types.ts.html +0 -412
  40. package/coverage/lcov-report/utils.ts.html +0 -145
  41. package/coverage/lcov.info +0 -268
  42. package/dist/compatible.d.ts +0 -10
  43. package/dist/compatible.d.ts.map +0 -1
  44. package/dist/constance.d.ts +0 -6
  45. package/dist/constance.d.ts.map +0 -1
  46. package/dist/cookie.d.ts +0 -8
  47. package/dist/cookie.d.ts.map +0 -1
  48. package/dist/dom.d.ts +0 -2
  49. package/dist/dom.d.ts.map +0 -1
  50. package/dist/index.js.LICENSE.txt +0 -1
  51. package/dist/request.d.ts +0 -36
  52. package/dist/request.d.ts.map +0 -1
  53. package/dist/shares.d.ts +0 -10
  54. package/dist/shares.d.ts.map +0 -1
  55. package/dist/test/cookie.test.d.ts +0 -2
  56. package/dist/test/cookie.test.d.ts.map +0 -1
  57. package/dist/test/shares.test.d.ts +0 -2
  58. package/dist/test/shares.test.d.ts.map +0 -1
  59. package/dist/types.d.ts +0 -89
  60. package/dist/types.d.ts.map +0 -1
  61. package/dist/utils.d.ts +0 -2
  62. package/dist/utils.d.ts.map +0 -1
  63. package/index.html +0 -28
  64. package/index.ts +0 -154
  65. package/jest.config.js +0 -6
  66. package/src/compatible.ts +0 -46
  67. package/src/constance.ts +0 -7
  68. package/src/cookie.ts +0 -75
  69. package/src/dom.ts +0 -59
  70. package/src/request.ts +0 -99
  71. package/src/shares.ts +0 -26
  72. package/src/types.ts +0 -109
  73. package/src/utils.ts +0 -20
  74. package/tests/compatible.test.ts +0 -420
  75. package/tests/cookie.test.ts +0 -78
  76. package/tests/dom.test.ts +0 -95
  77. package/tests/index.test.ts +0 -126
  78. package/tests/shares.test.ts +0 -52
  79. package/tests/utils.test.ts +0 -79
  80. package/tsconfig.json +0 -49
  81. package/webpack.config.mjs +0 -47
@@ -1,126 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import { describe, expect, test, jest, beforeEach, afterEach } from '@jest/globals'
5
- import { getUserInfo, make } from '../src/utils'
6
- import { Base64 } from 'js-base64'
7
- import {
8
- getAccessToken,
9
- getRefreshToken,
10
- setAccessToken,
11
- setRefreshToken,
12
- setSystemType
13
- } from '../src/cookie'
14
- import { openDialog } from '../src/dom'
15
- import {
16
- fetchServerListHTTP,
17
- fetchRefreshTokenHTTP,
18
- initInstance,
19
- fetchLogoutHTTP
20
- } from '../src/request'
21
- import {
22
- setTenantId,
23
- setBrand,
24
- setModuleBaseUrl,
25
- setLoginPageUrl
26
- } from '../src/shares'
27
- import { NO_ACCESS_TOKEN, NO_MODULE_BASE_URL, NO_REFRESH_TOKEN } from '../src/constance'
28
- import { SystemType } from '../src/types'
29
-
30
- jest.mock('../src/cookie', () => ({
31
- getAccessToken: jest.fn(),
32
- getRefreshToken: jest.fn(),
33
- setAccessToken: jest.fn(),
34
- setRefreshToken: jest.fn(),
35
- setSystemType: jest.fn()
36
- }))
37
-
38
- jest.mock('../src/dom', () => ({
39
- openDialog: jest.fn()
40
- }))
41
-
42
- jest.mock('../src/request', () => ({
43
- fetchServerListHTTP: jest.fn(),
44
- fetchRefreshTokenHTTP: jest.fn(),
45
- initInstance: jest.fn(),
46
- fetchLogoutHTTP: jest.fn()
47
- }))
48
-
49
- jest.mock('../src/shares', () => ({
50
- setTenantId: jest.fn(),
51
- setBrand: jest.fn(),
52
- setModuleBaseUrl: jest.fn(),
53
- setLoginPageUrl: jest.fn()
54
- }))
55
-
56
- // 模拟 js-base64
57
- jest.mock('js-base64', () => ({
58
- Base64: {
59
- decode: jest.fn()
60
- }
61
- }))
62
-
63
- describe('index.ts 入口文件单元测试', () => {
64
- // 模拟的定时器ID
65
- let mockTimerId: number
66
-
67
- beforeEach(() => {
68
- // 重置所有模拟
69
- jest.clearAllMocks()
70
-
71
- // 设置假定时器
72
- jest.useFakeTimers()
73
-
74
- // 初始化 mock 定时器ID
75
- mockTimerId = 123
76
- jest.spyOn(global, 'setInterval').mockImplementation(() => mockTimerId)
77
- jest.spyOn(global, 'clearInterval').mockImplementation(() => undefined)
78
-
79
- // 设置默认的 mock 返回值
80
- ;(getAccessToken as jest.Mock).mockReturnValue('mock.access.token')
81
- ;(getRefreshToken as jest.Mock).mockReturnValue('mock.refresh.token')
82
- ;(Base64.decode as jest.Mock).mockReturnValue(JSON.stringify({
83
- 'cognito:groups': ['testModule', 'commonLogin']
84
- }))
85
- ;(fetchServerListHTTP as jest.Mock).mockResolvedValue({
86
- data: {
87
- content: [
88
- {
89
- groupName: 'AdminPortal',
90
- staffEndpoint: true
91
- },
92
- {
93
- groupName: 'App',
94
- staffEndpoint: false
95
- }
96
- ]
97
- }
98
- })
99
- })
100
-
101
- afterEach(() => {
102
- // 恢复真定时器
103
- jest.useRealTimers()
104
- // 清理所有模拟
105
- jest.clearAllMocks()
106
- })
107
-
108
- describe('getUserInfo 函数', () => {
109
- test('应该正确解析 token 并返回用户信息', async () => {
110
- const mockUserInfo = {
111
- sub: '123456',
112
- email: 'test@example.com',
113
- 'cognito:groups': ['App']
114
- }
115
-
116
- ;(Base64.decode as jest.Mock).mockReturnValue(JSON.stringify(mockUserInfo))
117
-
118
- const result = await getUserInfo()
119
- console.log(result)
120
-
121
- expect(result).toEqual(mockUserInfo)
122
- expect(getAccessToken).toHaveBeenCalled()
123
- expect(Base64.decode).toHaveBeenCalledWith('mock.access.token'.split('.')[1])
124
- })
125
- })
126
- })
@@ -1,52 +0,0 @@
1
- import { describe, expect, test } from '@jest/globals'
2
- import {
3
- setBrand,
4
- setTenantId,
5
- setModuleBaseUrl,
6
- setLoginPageUrl,
7
- moduleBaseUrl,
8
- tenantId,
9
- brand,
10
- loginPageUrl
11
- } from '../src/shares'
12
- import { Brand, Tenant } from '../src/types'
13
-
14
- describe('shares.ts set tenant id 方法单元测试', () => {
15
- test('测试设置 tenant id 为 ZERO', () => {
16
- setTenantId(Tenant.ZERO_BR)
17
- expect(tenantId).toEqual(Tenant.ZERO_BR)
18
- })
19
-
20
- test('测试设置 tenant id 边界值情况', () => {
21
- expect(() => setTenantId('asd')).toThrow()
22
- })
23
- })
24
-
25
- describe('shares.ts set brand id 方法单元测试', () => {
26
- test('测试设置 brand id 为 ZERO', () => {
27
- setBrand(Brand.ZERO)
28
- expect(brand).toEqual(Brand.ZERO)
29
- })
30
-
31
- test('测试设置 brand id 边界值情况', () => {
32
- expect(() => setBrand('asd')).toThrow()
33
- })
34
- })
35
-
36
- describe('shares.ts set moduleBaseUrl 方法单元测试', () => {
37
- test('测试设置 moduleBaseUrl', () => {
38
- const testModuleBaseUrl = 'http://localhost:8080'
39
-
40
- setModuleBaseUrl(testModuleBaseUrl)
41
- expect(moduleBaseUrl).toEqual(testModuleBaseUrl)
42
- })
43
- })
44
-
45
- describe('shares.ts set loginPageUrl 方法单元测试', () => {
46
- test('测试设置 loginPageUrl', () => {
47
- const testLoginPageUrl = 'http://localhost:8080'
48
-
49
- setLoginPageUrl(testLoginPageUrl)
50
- expect(loginPageUrl).toEqual(testLoginPageUrl)
51
- })
52
- })
@@ -1,79 +0,0 @@
1
- import { describe, expect, test, jest, beforeEach } from '@jest/globals'
2
- import { isMobile } from '../src/utils'
3
-
4
- describe('isMobile 函数单元测试', () => {
5
- let originalNavigator: Navigator
6
-
7
- beforeEach(() => {
8
- originalNavigator = global.navigator
9
-
10
- // 重置所有 mock
11
- jest.clearAllMocks()
12
- })
13
-
14
- afterEach(() => {
15
- // 恢复原始 navigator
16
- if (originalNavigator) {
17
- Object.defineProperty(global, 'navigator', {
18
- value: originalNavigator,
19
- writable: true,
20
- configurable: true
21
- })
22
- }
23
- })
24
-
25
- describe('移动设备检测', () => {
26
- test('应该检测 Android 设备', () => {
27
- Object.defineProperty(global, 'navigator', {
28
- value: {
29
- userAgent: 'Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36'
30
- },
31
- writable: true,
32
- configurable: true
33
- })
34
-
35
- expect(isMobile()).toBe(true)
36
- })
37
-
38
- test('应该检测 iPhone 设备', () => {
39
- // 模拟 iPhone 设备的 userAgent
40
- Object.defineProperty(global, 'navigator', {
41
- value: {
42
- userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1'
43
- },
44
- writable: true,
45
- configurable: true
46
- })
47
-
48
- expect(isMobile()).toBe(true)
49
- })
50
-
51
- describe('桌面设备检测', () => {
52
- test('应该检测 Windows 桌面浏览器', () => {
53
- // 模拟 Windows 桌面浏览器的 userAgent
54
- Object.defineProperty(global, 'navigator', {
55
- value: {
56
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
57
- },
58
- writable: true,
59
- configurable: true
60
- })
61
-
62
- expect(isMobile()).toBe(false)
63
- })
64
- })
65
-
66
- test('应该检测 macOS 桌面浏览器', () => {
67
- // 模拟 macOS 桌面浏览器的 userAgent
68
- Object.defineProperty(global, 'navigator', {
69
- value: {
70
- userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
71
- },
72
- writable: true,
73
- configurable: true
74
- })
75
-
76
- expect(isMobile()).toBe(false)
77
- })
78
- })
79
- })
package/tsconfig.json DELETED
@@ -1,49 +0,0 @@
1
- {
2
- // Visit https://aka.ms/tsconfig to read more about this file
3
- "compilerOptions": {
4
- // File Layout
5
- // "rootDir": "./src",
6
- "outDir": "./dist",
7
-
8
- // Environment Settings
9
- // See also https://aka.ms/tsconfig/module
10
- "module": "esnext",
11
- "target": "esnext",
12
- "types": [],
13
- // For nodejs:
14
- "lib": ["esnext", "dom"],
15
- "moduleResolution": "bundler",
16
- // "types": ["node"],
17
- // and npm install -D @types/node
18
-
19
- // Other Outputs
20
- "sourceMap": false,
21
- "declaration": true,
22
- "declarationMap": true,
23
-
24
- // Stricter Typechecking Options
25
- "noUncheckedIndexedAccess": true,
26
- "exactOptionalPropertyTypes": true,
27
-
28
- // Style Options
29
- // "noImplicitReturns": true,
30
- // "noImplicitOverride": true,
31
- // "noUnusedLocals": true,
32
- // "noUnusedParameters": true,
33
- // "noFallthroughCasesInSwitch": true,
34
- // "noPropertyAccessFromIndexSignature": true,
35
-
36
- // Recommended Options
37
- "strict": true,
38
- "jsx": "react-jsx",
39
- "verbatimModuleSyntax": true,
40
- "isolatedModules": true,
41
- "noUncheckedSideEffectImports": true,
42
- "moduleDetection": "force",
43
- "skipLibCheck": true,
44
- "allowSyntheticDefaultImports": true
45
- },
46
- "exclude": [
47
- "tests"
48
- ]
49
- }
@@ -1,47 +0,0 @@
1
- // webpack.config.mjs
2
- import path from 'path'
3
-
4
- const baseConfig = {
5
- entry: './index.ts',
6
- mode: 'development',
7
- module: {
8
- rules: [
9
- {
10
- test: /\.ts$/,
11
- loader: 'ts-loader',
12
- }
13
- ]
14
- },
15
- resolve: {
16
- extensions: ['.ts', '.js'], // 将resolve配置移到baseConfig中
17
- }
18
- }
19
-
20
- export default [
21
- {
22
- ...baseConfig,
23
- output: {
24
- path: path.resolve(process.cwd(), './dist'),
25
- filename: 'index.umd.js',
26
- library: {
27
- type: 'umd',
28
- },
29
- globalObject: 'this',
30
- }
31
- },
32
- {
33
- ...baseConfig,
34
- output: {
35
- path: path.resolve(process.cwd(), './dist'),
36
- filename: 'index.esm.js',
37
- library: {
38
- type: 'module'
39
- },
40
- module: true,
41
- environment: { module: true }
42
- },
43
- experiments: {
44
- outputModule: true
45
- }
46
- }
47
- ]