@teleporthq/teleport-plugin-next-workflows 0.45.5 → 0.45.6
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/__tests__/account-delete-password-check.test.ts +39 -0
- package/__tests__/public-step-guards.test.ts +26 -0
- package/dist/cjs/account-delete-route-generator.d.ts.map +1 -1
- package/dist/cjs/account-delete-route-generator.js +17 -8
- package/dist/cjs/account-delete-route-generator.js.map +1 -1
- package/dist/cjs/public-step-guards.d.ts +2 -2
- package/dist/cjs/public-step-guards.d.ts.map +1 -1
- package/dist/cjs/public-step-guards.js +11 -8
- package/dist/cjs/public-step-guards.js.map +1 -1
- package/dist/cjs/publish-refusals.js +1 -1
- package/dist/cjs/publish-refusals.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/account-delete-route-generator.d.ts.map +1 -1
- package/dist/esm/account-delete-route-generator.js +17 -8
- package/dist/esm/account-delete-route-generator.js.map +1 -1
- package/dist/esm/public-step-guards.d.ts +2 -2
- package/dist/esm/public-step-guards.d.ts.map +1 -1
- package/dist/esm/public-step-guards.js +11 -8
- package/dist/esm/public-step-guards.js.map +1 -1
- package/dist/esm/publish-refusals.js +1 -1
- package/dist/esm/publish-refusals.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/account-delete-route-generator.ts +17 -8
- package/src/public-step-guards.ts +14 -8
- package/src/publish-refusals.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teleporthq/teleport-plugin-next-workflows",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.6",
|
|
4
4
|
"description": "A plugin for workflow code generation in Next.js projects.",
|
|
5
5
|
"author": "teleportHQ",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"@teleporthq/teleport-shared": "^0.45.0",
|
|
70
70
|
"@teleporthq/teleport-types": "^0.45.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "c31e265b69774868545e810e31a3c748f62a1729"
|
|
73
73
|
}
|
|
@@ -335,19 +335,28 @@ function readRequestPassword(req) {
|
|
|
335
335
|
return String(body.password);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
// The sign-in check (utils/auth/hash-password.js
|
|
339
|
-
// the SHA-256 of the password and
|
|
340
|
-
//
|
|
338
|
+
// The sign-in check (utils/auth/hash-password.js checkPassword): bcrypt over
|
|
339
|
+
// the SHA-256 of the password and a pepper, the project's own
|
|
340
|
+
// (AUTH_PEPPER_SECRET) first, then the one every earlier hash used
|
|
341
|
+
// (AUTH_PEPPER). An account without a stored password (a social sign-in)
|
|
342
|
+
// matches no password.
|
|
341
343
|
function passwordMatches(password, storedHash) {
|
|
342
344
|
if (!storedHash || password.length > 1000) { return false; }
|
|
343
345
|
var bcrypt = require('bcryptjs');
|
|
344
346
|
var crypto = require('crypto');
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
347
|
+
var secret = process.env.AUTH_PEPPER_SECRET;
|
|
348
|
+
var peppers = typeof secret === 'string' && secret && secret.indexOf('teleporthq.secrets.') !== 0
|
|
349
|
+
? [secret, process.env.AUTH_PEPPER || '']
|
|
350
|
+
: [process.env.AUTH_PEPPER || ''];
|
|
351
|
+
for (var i = 0; i < peppers.length; i++) {
|
|
352
|
+
var prepared = crypto.createHash('sha256').update(password + peppers[i]).digest('base64');
|
|
353
|
+
try {
|
|
354
|
+
if (bcrypt.compareSync(prepared, String(storedHash))) { return true; }
|
|
355
|
+
} catch (e) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
350
358
|
}
|
|
359
|
+
return false;
|
|
351
360
|
}
|
|
352
361
|
|
|
353
362
|
${generateFillTemplateFn()}
|
|
@@ -103,12 +103,18 @@ const adviceFor = (staffRoles: string[]): string =>
|
|
|
103
103
|
const SHORT_ADVICE =
|
|
104
104
|
'Let only an admin role start it (a role your admin-panel pages admit), or move it into a scheduled, signed webhook or automation workflow, then publish again.'
|
|
105
105
|
|
|
106
|
+
/** What to change on a site without accounts: no role can be required until it has them. */
|
|
107
|
+
const NO_ACCOUNTS_ADVICE =
|
|
108
|
+
'Your site has no sign-in, so no role can be required yet: enable authentication and let only an admin role start it, or move it into a scheduled, signed webhook or automation workflow, then publish again.'
|
|
109
|
+
|
|
106
110
|
/** One line of plain prose, for the person publishing. */
|
|
107
111
|
export const describePublicStepRefusals = (
|
|
108
112
|
refusals: PublicStepRefusal[],
|
|
109
|
-
staffRoles: string[] = [TableAccess.ADMIN_ROLE]
|
|
113
|
+
staffRoles: string[] = [TableAccess.ADMIN_ROLE],
|
|
114
|
+
hasAccounts = true
|
|
110
115
|
): string => {
|
|
111
|
-
const advice = adviceFor(staffRoles)
|
|
116
|
+
const advice = hasAccounts ? adviceFor(staffRoles) : NO_ACCOUNTS_ADVICE
|
|
117
|
+
const shortAdvice = hasAccounts ? SHORT_ADVICE : NO_ACCOUNTS_ADVICE
|
|
112
118
|
const listed = refusals.slice(0, LISTED_STEPS).map(describe)
|
|
113
119
|
const more = refusals.length - listed.length
|
|
114
120
|
const subject =
|
|
@@ -121,10 +127,10 @@ export const describePublicStepRefusals = (
|
|
|
121
127
|
)}${more > 0 ? `; and ${more} more` : ''}.`
|
|
122
128
|
for (const candidate of [
|
|
123
129
|
`${subject} ${advice}`,
|
|
124
|
-
`${subject} ${
|
|
130
|
+
`${subject} ${shortAdvice}`,
|
|
125
131
|
`On your site the step ${describe(refusals[0])}${
|
|
126
132
|
refusals.length > 1 ? `, and ${refusals.length - 1} more` : ''
|
|
127
|
-
}. ${
|
|
133
|
+
}. ${shortAdvice}`,
|
|
128
134
|
]) {
|
|
129
135
|
if (candidate.length <= MAX_SENTENCE_LENGTH) {
|
|
130
136
|
return candidate
|
|
@@ -132,7 +138,7 @@ export const describePublicStepRefusals = (
|
|
|
132
138
|
}
|
|
133
139
|
return `On your site ${
|
|
134
140
|
refusals.length === 1 ? 'a step' : `${refusals.length} steps`
|
|
135
|
-
} meant only for an admin or your own server (a push notification or a stored-file step) can be started by others. ${
|
|
141
|
+
} meant only for an admin or your own server (a push notification or a stored-file step) can be started by others. ${shortAdvice}`
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
/**
|
|
@@ -147,11 +153,11 @@ export class PublicStepRefusalError extends Error {
|
|
|
147
153
|
readonly code = PUBLIC_STEP_REFUSAL_CODE
|
|
148
154
|
readonly refusals: PublicStepRefusal[]
|
|
149
155
|
|
|
150
|
-
constructor(refusals: PublicStepRefusal[], staffRoles?: string[]) {
|
|
156
|
+
constructor(refusals: PublicStepRefusal[], staffRoles?: string[], hasAccounts?: boolean) {
|
|
151
157
|
super(
|
|
152
158
|
`Publishing refused: ${JSON.stringify({
|
|
153
159
|
code: PUBLIC_STEP_REFUSAL_CODE,
|
|
154
|
-
message: describePublicStepRefusals(refusals, staffRoles),
|
|
160
|
+
message: describePublicStepRefusals(refusals, staffRoles, hasAccounts),
|
|
155
161
|
steps: refusals.map((r) => ({ owner: r.ownerId, node: r.nodeId, type: r.nodeType })),
|
|
156
162
|
})}`
|
|
157
163
|
)
|
|
@@ -443,6 +449,6 @@ export const assertNoPublicRestrictedSteps = (
|
|
|
443
449
|
const staffRoles = TableAccess.resolveStaffRoles(authentication)
|
|
444
450
|
const refusals = findPublicRestrictedSteps(workflows, { staffRoles })
|
|
445
451
|
if (refusals.length > 0) {
|
|
446
|
-
throw new PublicStepRefusalError(refusals, staffRoles)
|
|
452
|
+
throw new PublicStepRefusalError(refusals, staffRoles, authentication?.enabled === true)
|
|
447
453
|
}
|
|
448
454
|
}
|
package/src/publish-refusals.ts
CHANGED
|
@@ -168,7 +168,7 @@ const publicStepRefusals = (
|
|
|
168
168
|
ownerId: refusal.ownerId,
|
|
169
169
|
ownerKind: refusal.ownerKind,
|
|
170
170
|
nodeId: refusal.nodeId,
|
|
171
|
-
message: describePublicStepRefusals([refusal], staffRoles),
|
|
171
|
+
message: describePublicStepRefusals([refusal], staffRoles, authentication?.enabled === true),
|
|
172
172
|
}))
|
|
173
173
|
}
|
|
174
174
|
|