@wral/studio.mods.auth 0.3.7

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/.eslintrc.mjs ADDED
@@ -0,0 +1,67 @@
1
+ export default {
2
+ languageOptions: {
3
+ ecmaVersion: 'latest',
4
+ sourceType: 'module',
5
+ ecmaFeatures: {
6
+ jsx: true, // Set to true if you're using JSX
7
+ },
8
+ globals: {
9
+ process: 'readonly',
10
+ require: 'readonly',
11
+ },
12
+ },
13
+ extends: [
14
+ 'eslint:recommended',
15
+ ],
16
+ overrides: [
17
+ {
18
+ files: ['.eslintrc.{js,cjs}'],
19
+ languageOptions: {
20
+ sourceType: 'script',
21
+ },
22
+ },
23
+ ],
24
+ ignorePatterns: [
25
+ 'node_modules',
26
+ 'dist',
27
+ 'docs',
28
+ ],
29
+ plugins: [
30
+ 'jest',
31
+ ],
32
+ rules: {
33
+ 'no-console': [ 'error' ],
34
+ 'no-unused-vars': [ 'error' ],
35
+ 'no-unused-private-class-members': [ 'error' ],
36
+ 'curly': [ 'error' ],
37
+ indent: [
38
+ 'error',
39
+ 'tab',
40
+ ],
41
+ 'no-tabs': ['off'],
42
+ 'linebreak-style': [
43
+ 'error',
44
+ 'unix',
45
+ ],
46
+ 'max-len': [
47
+ 'error',
48
+ {
49
+ code: 90,
50
+ comments: 80,
51
+ ignoreUrls: true,
52
+ ignoreRegExpLiterals: true,
53
+ },
54
+ ],
55
+ 'object-curly-spacing': ['off'],
56
+ 'comma-dangle': [
57
+ 'error',
58
+ {
59
+ arrays: 'always-multiline',
60
+ objects: 'always-multiline',
61
+ imports: 'always-multiline',
62
+ exports: 'always-multiline',
63
+ functions: 'ignore',
64
+ },
65
+ ],
66
+ },
67
+ };
@@ -0,0 +1 @@
1
+ npm run test && npm run lint
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Authentication Mod for Studio App
2
+
3
+ This is a mod for [Studio App](https://bitbucket.org/cbcnm/studio-app).
4
+
5
+ ## Installation
6
+
7
+ Include in your Studio App HTML implementation:
8
+
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>
27
+ ```
28
+
29
+ ## Usage
30
+
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
+ }
56
+ ```
@@ -0,0 +1,107 @@
1
+ ---
2
+ image: node:18-alpine
3
+
4
+ definitions:
5
+ caches:
6
+ npm: $HOME/.npm
7
+ steps:
8
+ - step: &lint
9
+ name: Check code syntax
10
+ caches:
11
+ - npm
12
+ - node
13
+ script:
14
+ - npm ci
15
+ - npm run lint
16
+ - step: &test
17
+ name: Run tests
18
+ image: node:18
19
+ caches:
20
+ - npm
21
+ - node
22
+ script:
23
+ - npm ci
24
+ - npx playwright install-deps
25
+ - npx playwright install chromium
26
+ - npm run test
27
+ artifacts:
28
+ - coverage/**
29
+ - step: &build
30
+ name: Build Distribution
31
+ caches:
32
+ - node
33
+ script:
34
+ - npm ci
35
+ - npm run build
36
+ artifacts:
37
+ - dist/**
38
+ - step: &publish-cdn
39
+ name: Publish to CDN
40
+ script:
41
+ - pipe: atlassian/aws-s3-deploy:0.3.8
42
+ variables:
43
+ AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
44
+ AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
45
+ AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
46
+ S3_BUCKET: ${S3_BUCKET}/mods/${MOD_NAME:-$BITBUCKET_REPO_SLUG}/release/${BITBUCKET_TAG}
47
+ LOCAL_PATH: 'dist'
48
+ - step: &publish-latest
49
+ name: Publish to CDN as latest version
50
+ script:
51
+ - pipe: atlassian/aws-s3-deploy:0.3.8
52
+ variables:
53
+ AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
54
+ AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
55
+ AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
56
+ S3_BUCKET: ${S3_BUCKET}/mods/${MOD_NAME:-$BITBUCKET_REPO_SLUG}/release/latest
57
+ LOCAL_PATH: 'dist'
58
+ - pipe: atlassian/aws-cloudfront-invalidate:0.1.1
59
+ variables:
60
+ AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
61
+ AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
62
+ AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
63
+ DISTRIBUTION_ID: ${AWS_DISTRIBUTION_ID}
64
+ PATHS: '/mods/${MOD_NAME:-$BITBUCKET_REPO_SLUG}/release/latest/*'
65
+ - step: &publish-npm
66
+ name: Publish to NPM
67
+ script:
68
+ - npm ci
69
+ # add "--tag $BITBUCKET_TAG" if not a semver
70
+ - |
71
+ if [[ $BITBUCKET_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
72
+ npm publish --access public
73
+ else
74
+ npm publish --access public --tag $BITBUCKET_TAG
75
+ fi
76
+ - step: &testify
77
+ name: Testify to the Witness
78
+ script:
79
+ - pipe: docker://public.ecr.aws/cbcrnd/pipe-witness-testify
80
+
81
+ pipelines:
82
+ default:
83
+ - parallel:
84
+ - step: *lint
85
+ - step: *test
86
+ - step: *testify
87
+
88
+ tags:
89
+ 'v*':
90
+ - parallel:
91
+ fail-fast: true
92
+ steps:
93
+ - step: *lint
94
+ - step: *test
95
+ - step: *build
96
+ - step: *publish-cdn
97
+ - step: *publish-npm
98
+ - step: *publish-latest
99
+ '*':
100
+ - parallel:
101
+ fail-fast: true
102
+ steps:
103
+ - step: *lint
104
+ - step: *test
105
+ - step: *build
106
+ - step: *publish-cdn
107
+ # - step: *publish-npm
@@ -0,0 +1,43 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Components</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="robots" content="noindex, nofollow">
8
+ <script type="module" src="./src/components/studio-login.mjs"></script>
9
+ <script type="module" src="./src/components/studio-reset-password.mjs"></script>
10
+ <script type="module" src="./src/components/studio-change-password.mjs"></script>
11
+ <!-- Load studio-app from CDN -->
12
+ </head>
13
+ <body>
14
+ <h1>Studio Auth Mod</h1>
15
+ <h2>Web Components</h2>
16
+ <div>
17
+ <h3>studio-login</h3>
18
+ <p>This represents a login form that uses the WRAL Auth API.</p>
19
+
20
+ <studio-login id="login"></studio-login>
21
+ <script>
22
+ const loginForm = document.querySelector('#login');
23
+ loginForm.addEventListener('login-attempt', console.log);
24
+ </script>
25
+
26
+ </div>
27
+ <div>
28
+ <h3>studio-reset-password</h3>
29
+ <p>This component provides an interface for requesting a password reset.</p>
30
+ <studio-reset-password></studio-reset-password>
31
+
32
+ <p>It can also be triggered with an existing confirmation code</p>
33
+ <studio-reset-password triggered confirmationCode="123456"
34
+ hideConfirmationCode></studio-reset-password>
35
+ </div>
36
+
37
+ <div>
38
+ <h3>studio-change-password</h3>
39
+ <p>This component provides an interface for requesting a password change.</p>
40
+ <studio-change-password></studio-change-password>
41
+ </div>
42
+ </body>
43
+ </html>
package/development.md ADDED
@@ -0,0 +1,41 @@
1
+ # Development Notes
2
+
3
+ ## Messages
4
+
5
+ This mod communicates with other mods in by publishing and subscribing to
6
+ events.
7
+
8
+ ### Requesting an Auth Token
9
+
10
+ Mods can request an auth token by publishing a `token-request` event with a
11
+ callback. The callback will be invoked with the token or an error if the
12
+ request fails.
13
+
14
+ #### Example
15
+
16
+ ```js
17
+ studio.pub('studio.wral::mod-auth', 'token-request', {
18
+ callback: (token, error) => {
19
+ if (error) {
20
+ console.error(error);
21
+ } else {
22
+ console.log(token);
23
+ }
24
+ },
25
+ });
26
+ ```
27
+
28
+ ## Publications
29
+
30
+ This mod publishes events for other mods to respond to.
31
+
32
+ ### Present login form
33
+
34
+ This mod publishes `system:auth::present-login-form` with the HTML for the login
35
+ form.
36
+
37
+ ```js
38
+ studio.pub('system:auth', 'present-login-form');
39
+ ```
40
+
41
+ This mod registers the `<login-form>` web component.