@wral/studio.mods.auth 0.3.7 → 1.0.0

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 (45) hide show
  1. package/README.md +39 -47
  2. package/bitbucket-pipelines.yml +25 -1
  3. package/dist/auth.cjs.js +326 -1467
  4. package/dist/auth.es.js +1081 -3093
  5. package/dist/lib.cjs.js +1 -1
  6. package/dist/lib.es.js +13 -7
  7. package/eslint.config.mjs +41 -34
  8. package/index.html +83 -18
  9. package/jest.config.mjs +24 -0
  10. package/jest.setup.mjs +5 -0
  11. package/package.json +15 -28
  12. package/src/auth.mjs +204 -69
  13. package/src/auth.test.mjs +97 -0
  14. package/src/components/auth-app.mjs +26 -0
  15. package/src/components/forgot-password-form.mjs +217 -0
  16. package/src/components/login-form.mjs +288 -0
  17. package/src/config.mjs +27 -0
  18. package/src/helper.mjs +31 -0
  19. package/src/helper.test.mjs +44 -0
  20. package/src/index.mjs +17 -0
  21. package/src/login-layout.mjs +32 -0
  22. package/src/login.mjs +20 -0
  23. package/src/routes/change-password.mjs +158 -0
  24. package/src/routes/dashboard.mjs +17 -0
  25. package/src/routes/index.mjs +15 -0
  26. package/src/state.mjs +61 -0
  27. package/src/state.test.mjs +58 -0
  28. package/src/styles.mjs +9 -0
  29. package/src/token.mjs +40 -0
  30. package/src/utils.mjs +3 -0
  31. package/vellum-fixture.mjs +86 -0
  32. package/vite.config.mjs +12 -0
  33. package/components.html +0 -43
  34. package/development.md +0 -41
  35. package/src/components/mod-auth-login-form.mjs +0 -133
  36. package/src/components/studio-change-password.mjs +0 -84
  37. package/src/components/studio-login.mjs +0 -94
  38. package/src/components/studio-profile-view.mjs +0 -56
  39. package/src/components/studio-reset-password.mjs +0 -110
  40. package/src/lib.mjs +0 -16
  41. package/src/tool-dummy.mjs +0 -84
  42. package/src/util.mjs +0 -194
  43. package/src/util.test.mjs +0 -171
  44. package/vite.config.js +0 -12
  45. package/web-test-runner.config.mjs +0 -28
package/README.md CHANGED
@@ -1,56 +1,48 @@
1
- # Authentication Mod for Studio App
1
+ # Vellum Auth Mod
2
2
 
3
- This is a mod for [Studio App](https://bitbucket.org/cbcnm/studio-app).
3
+ This mod provides an Authentication mechanism via JWTs.
4
4
 
5
- ## Installation
5
+ ## Usage
6
6
 
7
- Include in your Studio App HTML implementation:
7
+ In a vellum project, add the following mod:
8
8
 
9
9
  ```html
10
- <!doctype html>
11
- <html lang="en">
12
- <head>
13
- <meta charset="utf-8">
14
- <title>Your Studio App</title>
15
- <script type="module" src="https://cdn.wral.studio/studio-app.js"></script>
16
- <meta name="viewport" content="width=device-width, initial-scale=1">
17
- </head>
18
- <body>
19
- <studio-app>
20
-
21
- <!-- Hello, World! Studio Mod -->
22
- <studio-mod src="https://cdn.wral.studio/mods/auth/release/latest/auth.es.js"></studio-mod>
23
-
24
- </studio-app>
25
- </body>
26
- </html>
10
+ <vellum-app>
11
+ <vellum-mod name="auth" src="https://cdn.wral.studio/mods/auth/release/v1.0.0/auth.es.js"
12
+ api="https://api.wral.com/auth"
13
+ force-login>
14
+ </vellum-mod>
15
+ </vellum-app>
27
16
  ```
28
17
 
29
- ## Usage
18
+ ### Attributes
19
+ * `api`: _required_ auth api endpoint (without version or trailing slash)
20
+ * `force-login`: _optional_ force login on first page load
21
+ * session-key: _optional_ session key to use. Defaults to `token`
22
+
23
+ ### Requesting an auth token
24
+
25
+ Consuming apps that would like an Auth token should dispatch an event:
26
+
27
+ ```es6
28
+ const callback = (token) => {
29
+ // do something with the token
30
+ };
30
31
 
31
- The auth mod subscribes to the following:
32
-
33
- - `studio.wral::mod-auth`::`token-request`, payload: { callback: (token, error) => {} }
34
-
35
- The auth mod provides bearer tokens to other mods by request. Other mods can
36
- request a token by publishing a `token-request` event and providing a callback.
37
-
38
- ```js
39
- /**
40
- * @param {Studio} studio
41
- * @return {Promise<string>} bearer token
42
- */
43
- async function getToken(studio) {
44
- return new Promise((resolve, reject) => {
45
- studio.pub('studio.wral::mod-auth', 'token-request', {
46
- callback: (token, error) => {
47
- if (error) {
48
- reject(error);
49
- } else {
50
- resolve(token);
51
- }
52
- },
53
- });
54
- });
55
- }
32
+ toolkit.dispatchAction({
33
+ type: 'auth:requestToken',
34
+ detail: { callback },
35
+ });
56
36
  ```
37
+
38
+ Alternatively, `lib.es.js` contains a promise-based wrapper:
39
+ ```es6
40
+ import { getToken } from 'https://cdn.wral.studio/mods/auth/release/v1.0.0/lib.es.js';
41
+
42
+ const elem = document.querySelector('vellum-app'); // any element within the app
43
+
44
+ getToken(elem).then((token) => {
45
+ // do something with the token
46
+ });
47
+ ```
48
+
@@ -1,5 +1,5 @@
1
1
  ---
2
- image: node:18-alpine
2
+ image: node:22-alpine
3
3
 
4
4
  definitions:
5
5
  caches:
@@ -13,6 +13,10 @@ definitions:
13
13
  script:
14
14
  - npm ci
15
15
  - npm run lint
16
+ after-script:
17
+ - pipe: docker://public.ecr.aws/cbcrnd/pipe-witness-testify
18
+ variables:
19
+ FAIL_ONLY: 'true'
16
20
  - step: &test
17
21
  name: Run tests
18
22
  image: node:18
@@ -26,6 +30,10 @@ definitions:
26
30
  - npm run test
27
31
  artifacts:
28
32
  - coverage/**
33
+ after-script:
34
+ - pipe: docker://public.ecr.aws/cbcrnd/pipe-witness-testify
35
+ variables:
36
+ FAIL_ONLY: 'true'
29
37
  - step: &build
30
38
  name: Build Distribution
31
39
  caches:
@@ -35,6 +43,10 @@ definitions:
35
43
  - npm run build
36
44
  artifacts:
37
45
  - dist/**
46
+ after-script:
47
+ - pipe: docker://public.ecr.aws/cbcrnd/pipe-witness-testify
48
+ variables:
49
+ FAIL_ONLY: 'true'
38
50
  - step: &publish-cdn
39
51
  name: Publish to CDN
40
52
  script:
@@ -45,6 +57,10 @@ definitions:
45
57
  AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
46
58
  S3_BUCKET: ${S3_BUCKET}/mods/${MOD_NAME:-$BITBUCKET_REPO_SLUG}/release/${BITBUCKET_TAG}
47
59
  LOCAL_PATH: 'dist'
60
+ after-script:
61
+ - pipe: docker://public.ecr.aws/cbcrnd/pipe-witness-testify
62
+ variables:
63
+ FAIL_ONLY: 'true'
48
64
  - step: &publish-latest
49
65
  name: Publish to CDN as latest version
50
66
  script:
@@ -62,6 +78,10 @@ definitions:
62
78
  AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
63
79
  DISTRIBUTION_ID: ${AWS_DISTRIBUTION_ID}
64
80
  PATHS: '/mods/${MOD_NAME:-$BITBUCKET_REPO_SLUG}/release/latest/*'
81
+ after-script:
82
+ - pipe: docker://public.ecr.aws/cbcrnd/pipe-witness-testify
83
+ variables:
84
+ FAIL_ONLY: 'true'
65
85
  - step: &publish-npm
66
86
  name: Publish to NPM
67
87
  script:
@@ -73,6 +93,10 @@ definitions:
73
93
  else
74
94
  npm publish --access public --tag $BITBUCKET_TAG
75
95
  fi
96
+ after-script:
97
+ - pipe: docker://public.ecr.aws/cbcrnd/pipe-witness-testify
98
+ variables:
99
+ FAIL_ONLY: 'true'
76
100
  - step: &testify
77
101
  name: Testify to the Witness
78
102
  script: