@hellocoop/quickstart 2.2.1 → 2.3.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 CHANGED
@@ -1,45 +1,15 @@
1
1
  # Hellō Quickstart
2
2
 
3
+ This package starts a local web server and launches the Hellō Quickstart Web App to create or retrieve the `client_id` for a Hellō Application.
4
+
3
5
  ## CLI
4
6
 
5
- You can run the following command to create or retrieve the `client_id` for a Hellō Application.
7
+ If you have Node.js >= v18, you can run Quickstart with:
6
8
  ```sh
7
9
  npx @hellocoop/quickstart@latest
8
10
  ```
9
11
 
10
- This will open up a browser window, where you will need to login with Hellō, and then choose to create a new app, or return the `client_id`.
11
-
12
- ### Options
13
-
14
- - --provider_hint (-p) - space separated string of provider_hint
15
- - --suffix (-x) - suffix to add to generated app name
16
- - --integration (-i) - integration name shown in console
17
- - --file (-f) - file to write out HELLO_CLIENT_ID
18
- - --secret (-s) - boolean to generate a HELLO_COOKIE_SECRET value
19
- - --wildcard (-w) - boolean to set the wildcard domain Development Redirect URI
20
- - --debug (-d) - output debug info
21
-
12
+ This will prompt you to install the package if not already installed. It will then open up a browser window, where you will login with Hellō, and then choose to create a new app, or select an existing one, and then it will return the app's `client_id` to the console.
22
13
 
23
- ## Import Package
14
+ [Quickstart CLI and SDK Documentation](https://www.hello.dev/docs/sdks/quickstart)
24
15
 
25
- This package is useful for platform specific installers such as [Hellō Quickstart for Next.js](https://www.npmjs.com/package/@hellocoop/quickstart-nextjs)
26
-
27
- To install in another package
28
-
29
- ```sh
30
- npm i --save-dev @hellocoop/quickstart
31
- ```
32
-
33
- You can then use call Quickstart fom another configuration script
34
-
35
- ```javascript
36
- import quickstart from '@hellocoop/quickstart';
37
-
38
- ...
39
- const response_uri = 'http://localhost:8080'
40
- const client_id = await quickstart({
41
- response_uri
42
- })
43
-
44
- ```
45
- There are many options that can be passed to Quickstart. See the [Quickstart API](https://www.hello.dev/documentation/management-apis.html#quickstart-api) for details.
package/index.js CHANGED
@@ -67,8 +67,8 @@ const quickstart = async function (params) {
67
67
  const hellooDomain = process.env.HELLO_DOMAIN || 'hello.coop'
68
68
  const quickstartURL = `https://quickstart.${hellooDomain}/?${queryString}`
69
69
  server.listen(port, host, () => {
70
- console.log('\nObtaining a client_id with Hellō Quickstart')
71
- console.log("\n",chalk.blueBright(quickstartURL))
70
+ console.log('\nObtaining a client_id with Hellō Quickstart\n')
71
+ console.log(chalk.blueBright(quickstartURL))
72
72
  const rl = readline.createInterface({
73
73
  input: process.stdin,
74
74
  output: process.stdout
package/next.mjs ADDED
@@ -0,0 +1,108 @@
1
+ // next.js quickstart
2
+
3
+ import semver from 'semver';
4
+ import { statSync, appendFileSync } from 'fs'
5
+ import chalk from 'chalk';
6
+ import fs from 'fs-extra'
7
+ import 'dotenv/config'
8
+ import quickstart from './index.js';
9
+ import { randomBytes } from 'crypto'
10
+
11
+ const HELLO_CONFIG_FILE = 'hello.config.js'
12
+ const HELLO_COOP_FILE = 'pages/api/hellocoop.js'
13
+ const ENV_FILE = '.env.local'
14
+
15
+ // check if @hellocoop/nextjs is installed
16
+
17
+
18
+ const writeConfig = async (options) => {
19
+ const filePath = process.cwd()+'/'+HELLO_CONFIG_FILE
20
+ try {
21
+ statSync(filePath);
22
+ console.error(`${HELLO_CONFIG_FILE} already exists at:\n${filePath}\nSkipping getting client_id`)
23
+ return
24
+ } catch (err) {
25
+ if (err.code !== 'ENOENT') { // file does not exist
26
+ throw(err)
27
+ }
28
+ }
29
+ // file does not exist - let's get a client_id and write file
30
+ options.wildcard_domain=true
31
+ const client_id = await quickstart(options)
32
+ const config =`// ${HELLO_CONFIG_FILE}
33
+
34
+ const config = {
35
+ client_id: '${client_id}',
36
+ }
37
+ export default config
38
+ `
39
+ fs.outputFileSync( filePath, config)
40
+ console.log(`created ${filePath} with\nclient_id:${chalk.blueBright(client_id)}`)
41
+ // console.log(
42
+ // `You can update the:
43
+ // - Application Logo
44
+ // - Application Name
45
+ // - Terms of Service URL
46
+ // - Privacy Policy URL
47
+ // - Redirect URIs
48
+ // at the Hellō Developer Console https://console.hello.coop`)
49
+ }
50
+
51
+ const writeHelloCoop = async () => {
52
+ const filePath = process.cwd()+'/'+HELLO_COOP_FILE
53
+ try {
54
+ statSync(filePath);
55
+ console.error(`${HELLO_COOP_FILE} already exists at:\n${filePath}\nSkipping creating file`)
56
+ return
57
+ } catch (err) {
58
+ if (err.code !== 'ENOENT') { // file does not exist
59
+ throw(err)
60
+ }
61
+ }
62
+
63
+ const content = `// ${HELLO_COOP_FILE}
64
+
65
+ import config from '../../hello.config.js'
66
+ import { pageAuth } from '@hellocoop/nextjs'
67
+ export default pageAuth(config)
68
+ `
69
+ fs.outputFileSync( filePath, content )
70
+ }
71
+
72
+
73
+ const writeEnvLocal = async () => {
74
+ const existingSecret = process.env.HELLO_COOKIE_SECRET
75
+ if (existingSecret) {
76
+ console.error(`HELLO_COOKIE_SECRET already set to ${existingSecret}`)
77
+ return
78
+ }
79
+
80
+ const secret = randomBytes(32).toString('hex')
81
+ const env = `
82
+ # added by @hellocoop/quickstart --nextjs on ${(new Date()).toISOString()}
83
+ HELLO_COOKIE_SECRET='${secret}'
84
+ `
85
+ const outputFile = process.cwd()+'/'+ENV_FILE
86
+ appendFileSync(outputFile,env)
87
+ console.log(`\nUpdated ${outputFile} with:`)
88
+ console.log(chalk.blueBright(env))
89
+ }
90
+
91
+ const next = async (options) => {
92
+ try {
93
+ await writeHelloCoop()
94
+ await writeEnvLocal()
95
+ await writeConfig(options)
96
+ } catch (e) {
97
+ console.error(e)
98
+ process.exit(1)
99
+ }
100
+ }
101
+
102
+ export default next
103
+
104
+
105
+
106
+
107
+
108
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellocoop/quickstart",
3
- "version": "2.2.1",
3
+ "version": "2.3.2",
4
4
  "description": "A CLI and module to start the Hello Quickstart web app and return a client_id",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -32,10 +32,11 @@
32
32
  "bugs": {
33
33
  "url": "https://github.com/hellocoop/packages/issues"
34
34
  },
35
- "homepage": "https://github.com/hellocoop/packages#readme",
35
+ "homepage": "https://www.hello.dev/docs/sdk/quickstart",
36
36
  "dependencies": {
37
37
  "chalk": "^5.3.0",
38
38
  "dotenv": "^16.3.1",
39
+ "fs-extra": "^11.1.1",
39
40
  "get-port": "^7.0.0",
40
41
  "open": "^9.1.0",
41
42
  "semver": "^7.5.4"
package/page.js CHANGED
@@ -9,55 +9,16 @@ export default function (client_id) {
9
9
  <style>
10
10
  * { padding: 0; margin: 0; border: none; box-sizing: border-box; }
11
11
  html, body { height: 100%; }
12
- a { color: inherit;text-decoration: none; }
13
- a:hover, a:focus { text-decoration: underline; }
14
- a::after {
15
- content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" height="18" style="margin-left: 4px; margin-top: 4px; opacity: 0.8;" fill="none" viewBox="0 0 28 28" stroke="%23303030"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path></svg>')
16
- }
17
- .flash { animation: flash-animation 0.5s ease-in-out; }
18
- @keyframes flash-animation {
19
- 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; }
20
- }
21
12
  @media (prefers-color-scheme: dark) {
22
13
  body { background-color: #151515; }
23
14
  body, header, #client-id { color: #d4d4d4 !important; }
24
- #client-id { background-color: #303030 !important; }
25
- a::after { filter: invert(1); }
26
15
  }
27
16
  </style>
28
- <script>
29
- async function copyClientId() {
30
- await navigator.clipboard.writeText("${client_id}")
31
- //copy flash animation
32
- document.querySelector("#client-id").classList.add("flash")
33
- setTimeout(() => {
34
- document.querySelector("#client-id").classList.remove("flash")
35
- }, 500)
36
- }
37
- </script>
38
17
  </head>
39
18
  <body style="display: flex; flex-direction: column; color: #303030; font-family: ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;">
40
- <header style="background-color: #303030; color: white; height: 48px; display: flex; justify-content: center; align-items: center; font-size: 1.25rem; font-weight: 600;">Hellō Quickstart Result</header>
19
+ <header style="background-color: #303030; color: white; height: 48px; display: flex; justify-content: center; align-items: center; font-size: 1.25rem; font-weight: 600;">Hellō Quickstart Complete</header>
41
20
  <main style="flex: 1; padding: 24px; display: flex; flex-direction: column; align-items: center;">
42
- <div id="client-id-container" style="padding: 0 1rem; display: inline-flex; flex-direction: column; margin-top: 1rem;">
43
- <label for="client-id" style="font-size: 14px; font-weight: 500; text-align: left;">Client ID</label>
44
- <button id="client-id" onclick="copyClientId()" style="padding: 8px 0; height: auto; margin-top: 4px; text-align: left; border-radius: 6px; padding-left: 12px; padding-right: 12px; display: inline-flex; align-items: center; justify-content: center; background-color: #CBCFD5; color: #303030; font-size: 20px; cursor: pointer;">
45
- <span style="margin-right: 8px; font-family: monospace;">${client_id}</span>
46
- <svg xmlns="http://www.w3.org/2000/svg" fill="none" style="height: 1.25rem; width: 1.25rem" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
47
- </button>
48
- </div>
49
- <div style="margin-top: 24px; display: flex; flex-direction: column; align-items: flex-start;">
50
- You can update the:
51
- <ul style="margin: 10px 0; list-style-position: inside;">
52
- <li>Application Logo</li>
53
- <li>Application Name</li>
54
- <li>Terms of Service URL</li>
55
- <li>Privacy Policy URL</li>
56
- <li>Redirect URIs</li>
57
- </ul>
58
- <a href="https://console.hello.coop/?client_id=${client_id}" style="font-weight: 500;">at the Hellō Developer Console</a>
59
- </div>
60
- <p style="margin: 48px 0; font-size: 26px;">You may now close this window.</p>
21
+ <p style="margin: 48px 0; font-size: 26px;">you may now close this window</p>
61
22
  </main>
62
23
  </body>
63
24
  </html>`
package/quickstart.mjs CHANGED
@@ -1,6 +1,7 @@
1
- #!/usr/bin/env node
1
+ // quickstart CLI
2
+
2
3
  import semver from 'semver';
3
- import * as fs from 'fs'
4
+ import next from './next.mjs'
4
5
 
5
6
  const requiredVersion = '>=18.3.0';
6
7
 
@@ -11,7 +12,6 @@ if (!semver.satisfies(process.versions.node, requiredVersion)) {
11
12
 
12
13
  // following are in Nodejs 18+
13
14
  import { parseArgs } from "node:util";
14
- import { randomBytes } from 'crypto'
15
15
 
16
16
  if (!process.stdout.isTTY) {
17
17
  const error = new Error('Not running on interactive terminal. Exiting Hellō Quickstart.')
@@ -19,10 +19,13 @@ if (!process.stdout.isTTY) {
19
19
  process.exit(1);
20
20
  }
21
21
 
22
- const {
23
- values: { provider_hint, suffix, file, secret, wildcard, integration, debug },
22
+ let {
23
+ values: { nextjs, provider_hint, suffix, file, secret, wildcard, integration, debug },
24
24
  } = parseArgs({
25
25
  options: {
26
+ nextjs: {
27
+ type: "boolean"
28
+ },
26
29
  provider_hint: {
27
30
  type: "string",
28
31
  short: "p",
@@ -38,88 +41,33 @@ const {
38
41
  short: "i",
39
42
  default: ''
40
43
  },
41
- file: {
42
- type: "string",
43
- short: "f",
44
- },
45
- secret: {
46
- type: "boolean",
47
- short: "s",
48
- },
49
44
  wildcard: {
50
45
  type: "boolean",
51
46
  short: "w",
52
- },
53
- debug: {
54
- type: "boolean",
55
- short: "d",
56
- },
47
+ }
57
48
  },
58
49
  });
59
50
 
60
51
  import 'dotenv/config'
61
52
  import quickstart from './index.js';
62
53
 
63
- const existingClientId = process.env.HELLO_CLIENT_ID
64
- if (existingClientId) {
65
- console.error(`HELLO_CLIENT_ID already set to ${existingClientId}`)
66
- process.exit(0);
67
- }
68
-
69
- if (debug) {
70
- console.log('Hellō Quickstart parameters:')
71
- if (provider_hint)
72
- console.log(` provider_hint="${provider_hint}"`)
73
- if (suffix)
74
- console.log(` suffix="${suffix}"`)
75
- if (integration)
76
- console.log(` integration="${integration}"`)
77
- if (file)
78
- console.log(` writing output to "${file}"`)
79
- console.log(` generate secret=${secret}`)
80
- console.log(` enable wildcard=${wildcard}\n`);
81
- }
82
-
83
54
  (async () => {
84
55
 
85
- const options = {
86
- suffix,
87
- provider_hint,
88
- wildcard_domain: wildcard,
89
- integration
56
+ if (nextjs) {
57
+ await next({ provider_hint, suffix, integration })
58
+ process.exit(0)
90
59
  }
91
60
 
92
- const output = {}
93
- try {
94
- output.client_id = await quickstart(options)
95
- } catch(err) {
96
- console.error(err)
97
- process.exit(1)
98
- }
99
- if (secret)
100
- output.secret = randomBytes(32).toString('hex')
101
-
102
- if (file) {
103
- let helloConfig = `
104
- # added by @hellocoop/quickstart-nextjs on ${(new Date()).toISOString()}
105
- HELLO_CLIENT_ID='${output.client_id}'`
106
- if (secret) {
107
- helloConfig +=`
108
- HELLO_COOKIE_SECRET='${output.secret}'
109
- `
110
- }
111
- const outputFile = process.cwd()+'/'+file
112
-
113
- try {
114
- const err = fs.appendFileSync(outputFile,helloConfig)
115
- } catch(err) {
116
- console.err(err)
117
- process.exit(1)
118
- }
119
- console.log(`\nUpdated ${outputFile} with:`)
120
- console.log(helloConfig+'\n')
121
- } else {
122
- console.log(JSON.stringify(output,null,4))
123
- }
61
+ const options = {}
62
+ if (provider_hint)
63
+ options.provider_hint = provider_hint
64
+ if (suffix)
65
+ options.suffix = suffix
66
+ if (integration)
67
+ options.integration = integration
68
+ if (wildcard)
69
+ options.wildcard_domain = wildcard
124
70
 
71
+ const client_id = await quickstart(options)
72
+ console.log(`client_id=${client_id}`)
125
73
  })();