Skip to content

Commit 2cd5c49

Browse files
committed
Config now also has ticket expiration. The app now also checks for username, apptoken and usertoken in environment variables. The app also first authenticates (if necessary) using username and password, before continuously using only a ticket for all requests. A usertoken will be used preferentially if provided in config/envvar. Apptoken will be added if provided.
1 parent 19d1bad commit 2cd5c49

File tree

8 files changed

+250
-75
lines changed

8 files changed

+250
-75
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Below are the prompts (see the [Notes](#notes) below for an important advisory r
3131
```javascript
3232
{
3333
name: 'username',
34-
message: 'QuickBase username:'
34+
message: 'QuickBase username (leave blank to use the QUICKBASE_CLI_USERNAME environment variable):'
3535
},
3636
{
3737
name: 'password',
38-
message: 'QuickBase password (Leave blank to use the QUICKBASE_CLI_PASSWORD env variable):'
38+
message: 'QuickBase password (leave blank to use the QUICKBASE_CLI_PASSWORD environment variable):'
3939
},
4040
{
4141
name: 'dbid',
@@ -47,11 +47,19 @@ Below are the prompts (see the [Notes](#notes) below for an important advisory r
4747
},
4848
{
4949
name: 'appToken',
50-
message: 'QuickBase application token (if applicable):'
50+
message: 'QuickBase application token (if applicable) (leave blank to use the QUICKBASE_CLI_APPTOKEN environment variable):'
51+
},
52+
{
53+
name: 'userToken',
54+
message: 'QuickBase user token (if applicable) (leave blank to use the QUICKBASE_CLI_USERTOKEN environment variable):'
5155
},
5256
{
5357
name: 'appName',
5458
message: 'Code page prefix (leave blank to disable prefixing uploaded pages):'
59+
},
60+
{
61+
name: 'ticketExpiryHours',
62+
message: 'Ticket expiry period in hours (default is 1):'
5563
}
5664
```
5765

@@ -92,6 +100,8 @@ For now this is only a wrapper around `git clone`. After you pull down a repo yo
92100

93101
* Instead of exposing your password for the `quickbase-cli.config.js` file you can rely on an environment variable called `QUICKBASE_CLI_PASSWORD`. If you have that variable defined and leave the `password` empty when prompted the `qb deploy` command will use it instead. Always practice safe passwords.
94102

103+
* The same can also be done with username (using `QUICKBASE_CLI_USERNAME`), user token (using `QUICKBASE_CLI_USERTOKEN`) and/or app token (using `QUICKBASE_CLI_APPTOKEN`).
104+
95105
* ~~Moves are being made to add cool shit like a build process, global defaults, awesome starter templates, and pulling down existing code files from QuickBase. They're not out yet, so for now you're on your own.~~
96106

97107
* I no longer work with QuickBase applications, so the cool shit I had planned won't happen unless someone submits some dope pull requests.

bin/qb-deploy.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,45 @@ if (program.watch) {
4141
});
4242
}
4343

44+
4445
async function qbDeploy(source) {
4546
console.log('Uploading files to QuickBase...');
4647

4748
const stats = await fs.statSync(source);
4849
const isFile = stats.isFile();
4950

50-
if (isFile) {
51-
return uploadToQuickbase(source)
52-
.then(res =>
53-
console.log(`Successfully uploaded to QuickBase:\n=> ${source}`)
54-
)
55-
.catch(err => console.error(err));
56-
}
57-
58-
if (!isFile) {
59-
getFiles(source).then(files => {
60-
const uploadPromises = program.replace
61-
? files.map(file => replaceUrlsAndUpload(file, files))
62-
: files.map(file => uploadToQuickbase(file));
63-
64-
return Promise.all(uploadPromises)
51+
//We authenticate here, before we make a series of asynchronous api calls for each file
52+
api.authenticateIfNeeded().then((authType) => {
53+
54+
if (isFile) {
55+
return uploadToQuickbase(source)
6556
.then(res =>
66-
console.log(
67-
`Successfully uploaded to QuickBase:\n=> ${files.join('\n=> ')}`
68-
)
57+
console.log(`Successfully uploaded to QuickBase:\n=> ${source}`)
6958
)
7059
.catch(err => console.error(err));
71-
});
72-
}
60+
}
61+
62+
if (!isFile) {
63+
getFiles(source).then(files => {
64+
const uploadPromises = program.replace
65+
? files.map(file => replaceUrlsAndUpload(file, files))
66+
: files.map(file => uploadToQuickbase(file));
67+
68+
return Promise.all(uploadPromises)
69+
.then(res =>
70+
console.log(
71+
`Successfully uploaded to QuickBase:\n=> ${files.join('\n=> ')}`
72+
)
73+
)
74+
.catch(err => console.error(err));
75+
});
76+
}
77+
78+
}).catch((errorDesc) => console.error(errorDesc));
79+
7380
}
7481

82+
7583
function uploadToQuickbase(file, fileContents) {
7684
let fileName = path.basename(file);
7785
let codePageName;
@@ -89,6 +97,7 @@ function uploadToQuickbase(file, fileContents) {
8997
return api.uploadPage(codePageName, fileContents);
9098
}
9199

100+
92101
async function replaceUrlsAndUpload(file, allFiles) {
93102
let fileContents = await readFile(file, 'utf-8');
94103

@@ -107,12 +116,13 @@ async function replaceUrlsAndUpload(file, allFiles) {
107116
return uploadToQuickbase(file, fileContents);
108117
}
109118

119+
110120
function generateCustomPageUrl(fileName) {
111121
const suffix = config.appName
112122
? `${config.appName}-${fileName}`
113123
: `${fileName}`;
114124

115125
return `"https://${config.realm}.quickbase.com/db/${
116126
config.dbid
117-
}?a=dbpage&pagename=${suffix}"`;
127+
}?a=dbpage&pagename=${suffix}"`;
118128
}

bin/qb-init.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const QUESTIONS = [
88
{
99
type: 'input',
1010
name: 'username',
11-
message: 'QuickBase username:'
11+
message: 'QuickBase username (leave blank to use the QUICKBASE_CLI_USERNAME environment variable):'
1212
},
1313
{
1414
type: 'password',
@@ -29,13 +29,24 @@ const QUESTIONS = [
2929
{
3030
type: 'input',
3131
name: 'appToken',
32-
message: 'QuickBase application token (if applicable):'
32+
message: 'QuickBase application token (if applicable) (leave blank to use the QUICKBASE_CLI_APPTOKEN environment variable):'
33+
},
34+
{
35+
type: 'input',
36+
name: 'userToken',
37+
message: 'QuickBase user token (if applicable) (leave blank to use the QUICKBASE_CLI_USERTOKEN environment variable):'
3338
},
3439
{
3540
type: 'input',
3641
name: 'appName',
3742
message:
3843
'Code page prefix (leave blank to disable prefixing uploaded pages):'
44+
},
45+
{
46+
type: 'input',
47+
name: 'ticketExpiryHours',
48+
message:
49+
'Ticket expiry period in hours (default is 1):'
3950
}
4051
];
4152

demo/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
</head>
88
<body>
99
<h1>Hello, world</h1>
10-
10+
<p>This is a page, that should be deployed using quickbase-cli to quickbase, with styling and scripts properly referenced.</p>
11+
<p class="check_css">If this paragraph is bold, CSS files are properly referenced.</p>
12+
<p class="check_js">If this paragraph is bold, JS files are properly referenced.</p>
1113
<script src="static/bundle.js"></script>
1214
</body>
1315
</html>

demo/static/bundle.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
console.log('Hello from bundle.js');
2+
var elements = document.getElementsByClassName('check_js');
3+
var checkJsElement = elements[0];
4+
checkJsElement.style.fontWeight = 'bold';

demo/static/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
body {
22
font-family: sans-serif;
33
}
4+
5+
.check_css {
6+
font-weight: bold;
7+
}

0 commit comments

Comments
 (0)