@hellocoop/quickstart 2.3.0 → 2.3.3

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/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.3.0",
3
+ "version": "2.3.3",
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/quickstart.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
+
2
3
  import semver from 'semver';
3
- import * as fs from 'fs'
4
- import chalk from 'chalk';
4
+ import next from './next.mjs'
5
5
 
6
6
  const requiredVersion = '>=18.3.0';
7
7
 
@@ -12,7 +12,6 @@ if (!semver.satisfies(process.versions.node, requiredVersion)) {
12
12
 
13
13
  // following are in Nodejs 18+
14
14
  import { parseArgs } from "node:util";
15
- import { randomBytes } from 'crypto'
16
15
 
17
16
  if (!process.stdout.isTTY) {
18
17
  const error = new Error('Not running on interactive terminal. Exiting Hellō Quickstart.')
@@ -42,107 +41,33 @@ let {
42
41
  short: "i",
43
42
  default: ''
44
43
  },
45
- file: {
46
- type: "string",
47
- short: "f",
48
- },
49
- secret: {
50
- type: "boolean",
51
- short: "s",
52
- },
53
44
  wildcard: {
54
45
  type: "boolean",
55
46
  short: "w",
56
- },
57
- debug: {
58
- type: "boolean",
59
- short: "d",
60
- },
47
+ }
61
48
  },
62
49
  });
63
50
 
64
51
  import 'dotenv/config'
65
52
  import quickstart from './index.js';
66
53
 
67
- const existingClientId = process.env.HELLO_CLIENT_ID
68
- if (existingClientId) {
69
- console.error(`HELLO_CLIENT_ID already set to ${existingClientId}`)
70
- process.exit(0);
71
- }
72
-
73
- if (nextjs) {
74
- wildcard = true
75
- secret = true
76
- file = '.env'
77
- provider_hint = 'github gitlab google email--'
78
- }
79
-
80
-
81
- const options = {}
82
-
83
- debug && console.log('Hellō Quickstart parameters:')
84
- if (provider_hint) {
85
- options.provider_hint = provider_hint
86
- debug && console.log(` provider_hint="${provider_hint}"`)
87
- }
88
- if (suffix) {
89
- options.suffix = suffix
90
- debug && console.log(` suffix="${suffix}"`)
91
- }
92
- if (integration) {
93
- options.integration = integration
94
- debug && console.log(` integration="${integration}"`)
95
- }
96
- if (file) {
97
- debug && console.log(` writing output to "${file}"`)
98
- }
99
- if (wildcard) {
100
- options.wildcard_domain = wildcard
101
- debug && console.log(` enable wildcard=${wildcard}\n`);
102
- }
103
-
104
- debug && console.log(` generate secret=${secret}`);
105
-
106
-
107
54
  (async () => {
108
55
 
109
- const output = {}
110
- try {
111
- output.client_id = await quickstart(options)
112
- } catch(err) {
113
- console.error(err)
114
- process.exit(1)
115
- }
116
- if (secret)
117
- output.secret = randomBytes(32).toString('hex')
118
-
119
- if (file) {
120
- let helloConfig = `
121
- # added by @hellocoop/quickstart-nextjs on ${(new Date()).toISOString()}
122
- HELLO_CLIENT_ID='${output.client_id}'`
123
- if (secret) {
124
- helloConfig +=`
125
- HELLO_COOKIE_SECRET='${output.secret}'
126
- `
127
- }
128
- const outputFile = process.cwd()+'/'+file
129
-
130
- try {
131
- const err = fs.appendFileSync(outputFile,helloConfig)
132
- } catch(err) {
133
- console.err(err)
134
- process.exit(1)
135
- }
136
- console.log(`\nUpdated ${outputFile} with:`)
137
- console.log(chalk.blueBright(helloConfig))
138
- console.log(
139
- `You can update the:
140
- - Application Logo
141
- - Application Name
142
- - Terms of Service URL
143
- - Privacy Policy URL
144
- - Redirect URIs
145
- at the Hellō Developer Console https://console.hello.coop`)
56
+ if (nextjs) {
57
+ await next({ provider_hint, suffix, integration })
58
+ process.exit(0)
146
59
  }
147
60
 
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
70
+
71
+ const client_id = await quickstart(options)
72
+ console.log(`client_id=${client_id}`)
148
73
  })();