Skip to content

Commit

Permalink
Merge pull request #19 from FlowFuse/rebrand
Browse files Browse the repository at this point in the history
Rebrand and move to flowfuse npm scope
  • Loading branch information
knolleary committed Oct 24, 2023
2 parents 49f35ea + a732d0f commit 4d9891b
Show file tree
Hide file tree
Showing 13 changed files with 7,191 additions and 67 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
package-lock.json
dist/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 0.3.0 Release

- Rebrand to FlowFuse and migrate to @flowfuse npm scope

#### 0.2.0 Release

- Relabel projects to instances (#11) @knolleary
Expand Down
7,122 changes: 7,122 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flowforge/nr-tools-plugin",
"version": "0.2.0",
"name": "@flowfuse/nr-tools-plugin",
"version": "0.3.0",
"description": "A Node-RED plugin that adds FlowFuse platform tools to the editor",
"scripts": {
"build": "rollup -c",
Expand All @@ -21,7 +21,7 @@
"homepage": "https://flowfuse.com/docs/migration/node-red-tools/",
"node-red": {
"plugins": {
"flowforge-nr-tools": "dist/plugin.js"
"flowfuse-nr-tools": "dist/plugin.js"
}
},
"keywords": [
Expand Down
15 changes: 7 additions & 8 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { ffGet, ffPost } = require('./client')
function setupRoutes (RED) {
auth.setupRoutes(RED)

RED.httpAdmin.get('/flowforge-nr-tools/settings', async (request, response) => {
RED.httpAdmin.get('/flowfuse-nr-tools/settings', async (request, response) => {
const body = settings.exportPublicSettings()

const token = auth.getUserTokenForRequest(request)
Expand Down Expand Up @@ -36,9 +36,9 @@ function setupRoutes (RED) {
})

// ** All routes after this point must have a valid FF Token associated with the session **
RED.httpAdmin.use('/flowforge-nr-tools/*', auth.needsFFToken)
RED.httpAdmin.use('/flowfuse-nr-tools/*', auth.needsFFToken)

RED.httpAdmin.get('/flowforge-nr-tools/teams', async (request, response) => {
RED.httpAdmin.get('/flowfuse-nr-tools/teams', async (request, response) => {
try {
const teams = await ffGet('/api/v1/user/teams', request.ffToken)
response.send(teams)
Expand All @@ -47,7 +47,7 @@ function setupRoutes (RED) {
}
})

RED.httpAdmin.get('/flowforge-nr-tools/teams/:teamId/projects', async (request, response) => {
RED.httpAdmin.get('/flowfuse-nr-tools/teams/:teamId/projects', async (request, response) => {
try {
const projects = await ffGet(`/api/v1/teams/${request.params.teamId}/projects`, request.ffToken)
response.send(projects)
Expand All @@ -56,7 +56,7 @@ function setupRoutes (RED) {
}
})

RED.httpAdmin.get('/flowforge-nr-tools/projects/:projectId', async (request, response) => {
RED.httpAdmin.get('/flowfuse-nr-tools/projects/:projectId', async (request, response) => {
try {
const project = await ffGet(`/api/v1/projects/${request.params.projectId}`, request.ffToken)
response.send(project)
Expand All @@ -65,7 +65,7 @@ function setupRoutes (RED) {
}
})

RED.httpAdmin.get('/flowforge-nr-tools/projects/:projectId/snapshots', async (request, response) => {
RED.httpAdmin.get('/flowfuse-nr-tools/projects/:projectId/snapshots', async (request, response) => {
try {
const project = await ffGet(`/api/v1/projects/${request.params.projectId}/snapshots`, request.ffToken)
response.send(project)
Expand All @@ -74,7 +74,7 @@ function setupRoutes (RED) {
}
})

RED.httpAdmin.post('/flowforge-nr-tools/projects/:projectId/snapshots', async (request, response) => {
RED.httpAdmin.post('/flowfuse-nr-tools/projects/:projectId/snapshots', async (request, response) => {
try {
const flows = []
const credentials = {}
Expand All @@ -94,7 +94,6 @@ function setupRoutes (RED) {
flows,
credentials
}
// console.log(snapshot)
await ffPost(`/api/v1/projects/${request.params.projectId}/snapshots`, request.ffToken, snapshot)
response.send({})
} catch (err) {
Expand Down
22 changes: 11 additions & 11 deletions src/lib/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function refreshToken (token) {
}

function setupRoutes (RED) {
RED.httpAdmin.get('/flowforge-nr-tools/auth/authorize', (request, response) => {
RED.httpAdmin.get('/flowfuse-nr-tools/auth/authorize', (request, response) => {
const existingRequest = store.getRequest(request.query.s)
if (!existingRequest) {
return response.send(404)
Expand All @@ -96,9 +96,9 @@ function setupRoutes (RED) {
response.redirect(authURL.toString())
})

RED.httpAdmin.get('/flowforge-nr-tools/auth/callback', async (request, response) => {
RED.httpAdmin.get('/flowfuse-nr-tools/auth/callback', async (request, response) => {
if (request.query.error) {
const postMessage = JSON.stringify({ code: 'flowforge-auth-error', error: request.query.error, message: request.query.errorDescription })
const postMessage = JSON.stringify({ code: 'flowfuse-auth-error', error: request.query.error, message: request.query.errorDescription })
response.send(`
<html><head>
<script>
Expand Down Expand Up @@ -134,7 +134,7 @@ if (window.opener) {
if (statusCode === 200) {
const tokens = await body.json()
setUserToken(originalRequest.user, tokens)
const postMessage = JSON.stringify({ code: 'flowforge-auth-complete', state: originalRequest.state })
const postMessage = JSON.stringify({ code: 'flowfuse-auth-complete', state: originalRequest.state })
response.send(`
<html><head>
<script>
Expand All @@ -143,14 +143,14 @@ if (window.opener) {
window.close()
}
</script>
</head><body>Success! You're connected to FlowForge. You can now close this window to continue.</body></html>
</head><body>Success! You're connected to FlowFuse. You can now close this window to continue.</body></html>
`)
}
})
// ** All routes after this point must have a valid Node-RED session user **
RED.httpAdmin.use('/flowforge-nr-tools/*', RED.auth.needsPermission('flowforge.write'))
RED.httpAdmin.use('/flowfuse-nr-tools/*', RED.auth.needsPermission('flowfuse.write'))

RED.httpAdmin.post('/flowforge-nr-tools/auth/start', async (request, response) => {
RED.httpAdmin.post('/flowfuse-nr-tools/auth/start', async (request, response) => {
// This request is made from the editor, so will have the Node-RED user attached.
// Generate the login url for the auth pop-up window
if (request.body.forgeURL) {
Expand All @@ -161,20 +161,20 @@ if (window.opener) {
// Ping the server to check it is responsive and looks like a valid FF endpoint
ffGet('/api/v1/settings').then(result => {
const state = base64url(crypto.randomBytes(16))
const redirect = request.body.editorURL + (request.body.editorURL.endsWith('/') ? '' : '/') + 'flowforge-nr-tools/auth/callback'
const redirect = request.body.editorURL + (request.body.editorURL.endsWith('/') ? '' : '/') + 'flowfuse-nr-tools/auth/callback'
store.storeRequest({
user: getUserForRequest(request),
state,
redirect_uri: redirect
})
const authPath = 'flowforge-nr-tools/auth/authorize?s=' + state
const authPath = 'flowfuse-nr-tools/auth/authorize?s=' + state
response.send({ path: authPath, state })
}).catch(err => {
RED.log.error(`[flowforge-nr-tools] Failed to connect to server: ${err.toString()}`)
RED.log.error(`[flowfuse-nr-tools] Failed to connect to server: ${err.toString()}`)
response.send({ error: err.toString(), code: 'connect_failed' })
})
})
RED.httpAdmin.post('/flowforge-nr-tools/auth/disconnect', async (request, response) => {
RED.httpAdmin.post('/flowfuse-nr-tools/auth/disconnect', async (request, response) => {
// This request is made from the editor, so will have the Node-RED user attached.
deleteUserTokenForRequest(request)
response.send({ })
Expand Down
4 changes: 2 additions & 2 deletions src/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const settings = require('./settings')
const api = require('./api')
module.exports = (RED) => {
RED.plugins.registerPlugin('flowforge-nr-tools', {
RED.plugins.registerPlugin('flowfuse-nr-tools', {
settings: {
'*': { exportable: true }
},
Expand All @@ -11,7 +11,7 @@ module.exports = (RED) => {
// This is a bit of a hack, but it lets the plugin know when the
// comms connection has been established - such as after a runtime
// restart
RED.comms.publish('flowforge-nr-tools/connected', true, true)
RED.comms.publish('flowfuse-nr-tools/connected', true, true)
}
})
}
26 changes: 13 additions & 13 deletions src/ui/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function checkResponse (response) {
export async function refreshSettings () {
try {
settings = await $.ajax({
url: 'flowforge-nr-tools/settings/',
url: 'flowfuse-nr-tools/settings/',
type: 'GET'
})
if (settings.connected) {
Expand All @@ -34,12 +34,12 @@ export async function refreshSettings () {
export function connect (forgeURL, done) {
forgeURL = forgeURL || settings.forgeURL
if (!forgeURL) {
RED.notify('Please provide a FlowForge Server URL', 'error')
RED.notify('Please provide a FlowFuse Server URL', 'error')
return
}
$.ajax({
contentType: 'application/json',
url: 'flowforge-nr-tools/auth/start',
url: 'flowfuse-nr-tools/auth/start',
method: 'POST',
data: JSON.stringify({
forgeURL,
Expand All @@ -50,12 +50,12 @@ export function connect (forgeURL, done) {
const handleAuthCallback = function (evt) {
try {
const message = JSON.parse(evt.data)
if (message.code === 'flowforge-auth-complete') {
if (message.code === 'flowfuse-auth-complete') {
if (message.state === data.state) {
refreshSettings()
}
} else if (message.code === 'flowforge-auth-error') {
RED.notify('Failed to connect to FlowForge: ' + message.message, 'error')
} else if (message.code === 'flowfuse-auth-error') {
RED.notify('Failed to connect to FlowFuse: ' + message.message, 'error')
refreshSettings()
}
} catch (err) {}
Expand All @@ -64,7 +64,7 @@ export function connect (forgeURL, done) {
done()
}
}
window.open(document.location.toString().replace(/[?#].*$/, '') + data.path, 'FlowForgeNodeREDPluginAuthWindow', 'menubar=no,location=no,toolbar=no,chrome,height=650,width=500')
window.open(document.location.toString().replace(/[?#].*$/, '') + data.path, 'FlowFuseNodeREDPluginAuthWindow', 'menubar=no,location=no,toolbar=no,chrome,height=650,width=500')
window.addEventListener('message', handleAuthCallback, false)
} else if (data && data.error) {
RED.notify(`Failed to connect to server: ${data.error}`, { type: 'error' })
Expand All @@ -73,7 +73,7 @@ export function connect (forgeURL, done) {
}

export function disconnect (done) {
$.post('flowforge-nr-tools/auth/disconnect').then(data => {
$.post('flowfuse-nr-tools/auth/disconnect').then(data => {
refreshSettings()
if (done) {
done()
Expand All @@ -86,23 +86,23 @@ export function getSettings () {
}

export async function getUserTeams () {
return checkResponse(await $.getJSON('flowforge-nr-tools/teams'))
return checkResponse(await $.getJSON('flowfuse-nr-tools/teams'))
}

export async function getTeamProjects (teamId) {
return checkResponse(await $.getJSON(`flowforge-nr-tools/teams/${teamId}/projects`))
return checkResponse(await $.getJSON(`flowfuse-nr-tools/teams/${teamId}/projects`))
}
export async function getProject (projectId) {
return checkResponse(await $.getJSON(`flowforge-nr-tools/projects/${projectId}`))
return checkResponse(await $.getJSON(`flowfuse-nr-tools/projects/${projectId}`))
}
export async function getProjectSnapshots (projectId) {
return checkResponse(await $.getJSON(`flowforge-nr-tools/projects/${projectId}/snapshots`))
return checkResponse(await $.getJSON(`flowfuse-nr-tools/projects/${projectId}/snapshots`))
}

export async function createProjectSnapshot (projectId, options) {
return checkResponse(await $.ajax({
type: 'POST',
url: `flowforge-nr-tools/projects/${projectId}/snapshots`,
url: `flowfuse-nr-tools/projects/${projectId}/snapshots`,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(options)
}))
Expand Down
2 changes: 1 addition & 1 deletion src/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as sidebar from './sidebar'
import * as settingsPane from './views/settingsPane'
// import * as api from './api.js'

RED.plugins.registerPlugin('flowforge-nr-tools', {
RED.plugins.registerPlugin('flowfuse-nr-tools', {
onadd: async function () {
sidebar.init()
settingsPane.init()
Expand Down
18 changes: 9 additions & 9 deletions src/ui/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function init () {
const content = $(sidebarContentTemplate)
content.find('#ff-nr-tools-show-settings').on('click', function (evt) {
evt.preventDefault()
RED.userSettings.show('flowforge-nr-tools')
RED.userSettings.show('flowfuse-nr-tools')
})
const contentBody = content.find('#ff-nr-tools-body')
const toolbar = $(sidebarToolbarTemplate)
Expand Down Expand Up @@ -72,19 +72,19 @@ function init () {
})

RED.sidebar.addTab({
id: 'flowforge-nr-tools',
label: 'FlowForge',
name: 'FlowForge Tools',
id: 'flowfuse-nr-tools',
label: 'FlowFuse',
name: 'FlowFuse Tools',
content,
toolbar,
pinned: true,
iconClass: 'flowforge-nr-tools-icon',
action: 'flowforge-nr-tools:show-flowforge-tools-tab'
iconClass: 'flowfuse-nr-tools-icon',
action: 'flowfuse-nr-tools:show-flowfuse-tools-tab'
})
RED.actions.add('flowforge-nr-tools:show-flowforge-tools-tab', function () {
RED.sidebar.show('flowforge-nr-tools')
RED.actions.add('flowfuse-nr-tools:show-flowfuse-tools-tab', function () {
RED.sidebar.show('flowfuse-nr-tools')
})
RED.comms.subscribe('flowforge-nr-tools/connected', function (topic, msg) {
RED.comms.subscribe('flowfuse-nr-tools/connected', function (topic, msg) {
api.refreshSettings()
})
}
Expand Down
10 changes: 5 additions & 5 deletions src/ui/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.flowforge-nr-tools-icon {
.flowfuse-nr-tools-icon {
width: 14px;
height: 14px;
display: inline-block;
-webkit-mask-image: url(resources/@flowforge/nr-tools-plugin/ff-nr.png);
mask-image: url(resources/@flowforge/nr-tools-plugin/ff-nr.png);
-webkit-mask-image: url(resources/@flowfuse/nr-tools-plugin/ff-nr.png);
mask-image: url(resources/@flowfuse/nr-tools-plugin/ff-nr.png);
-webkit-mask-size: contain;
mask-size: contain;
-webkit-mask-position: 50% 50%;
Expand All @@ -12,13 +12,13 @@
mask-repeat: no-repeat;
background-color: var(--red-ui-workspace-button-color);
}
.red-ui-tab .flowforge-nr-tools-icon {
.red-ui-tab .flowfuse-nr-tools-icon {
width: 16px !important;
height: 16px !important;
margin-right: 7px !important;
margin-left: -5px !important;
}
.red-ui-menu .flowforge-nr-tools-icon {
.red-ui-menu .flowfuse-nr-tools-icon {
float: left;
width: 13px;
height: 13px;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/loginPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const loginPane = {

const settings = getSettings()
if (!settings.forgeURL) {
$('<div>To connect to FlowForge, open <i class="fa fa-cog"></i> Settings and set the Server URL</div>').appendTo(pane)
$('<div>To connect to FlowFuse, open <i class="fa fa-cog"></i> Settings and set the Server URL</div>').appendTo(pane)
} else {
$('<button type="button" class="red-ui-button">Connect to FlowForge</button>').appendTo(pane).on('click', function (evt) { connect() })
$('<button type="button" class="red-ui-button">Connect to FlowFuse</button>').appendTo(pane).on('click', function (evt) { connect() })
}
return pane
}
Expand Down

0 comments on commit 4d9891b

Please sign in to comment.