npm.io
1.0.2 • Published 4d ago

@inteli.city/node-red-contrib-drive-collection

Licence
Apache-2.0
Version
1.0.2
Deps
2
Size
55 kB
Vulns
0
Weekly
92

node-red-contrib-drive-collection

Node-RED nodes for Google Drive and OneDrive file operations.

A single drive node performs all operations (upload, download, list, delete) against a provider chosen on the linked drive-config.


Nodes

Node Type Purpose
drive-config config Provider selection + OAuth2 credentials
drive operation upload / download / list / delete

drive-config

Shared credentials and provider selection.

Field Description
Provider Google Drive or OneDrive
Tenant ID Azure AD tenant (OneDrive only)
Client ID OAuth2 client ID
Client Secret Stored as a credential
Refresh Token Paste manually from your OAuth flow

The access token is refreshed automatically in memory and is never persisted.

Environment variables

Any drive-config field may reference environment variables with the ${VAR_NAME} syntax — no special mode or control to enable, just type it into the existing field:

${REFRESH_TOKEN}
${TENANT_ID}
client-${ENV}
Aspect Behavior
Supported syntax ${VAR_NAME}, multiple references per value, and interpolation inside a larger string (e.g. client-${ENV}).
Not supported Default values (${VAR:-x}), nested variables, expressions, and flow/global context references. Anything that is not a plain ${NAME} reference is left as a literal.
Resolution At runtime, against process.env. Stored configuration is never mutated and resolved values are never written back.
Missing variable The operation fails clearly with code MISSING_ENV_VAR and an error naming the variable (e.g. Environment variable not set: REFRESH_TOKEN). Missing variables are never silently replaced with empty values.
Secrets Only variable names appear in logs, errors, and status. Resolved values are never logged or exposed. Labels keep showing the literal configured value (e.g. ${VAR}), not the resolved one.

This works for every field a config node stores — text, identifiers, paths, and credential fields alike.


drive

Unified node. Pick an operation in the editor (or override per-message via msg.operation).

Operations
Operation Required input Output
upload source per Input Source mode msg.payload = metadata, msg.fileId = uploaded ID
download fileId per Output Target mode (see below)
list none (defaults to root) msg.payload = array of file metadata
delete fileId (or path for OneDrive) msg.payload = { deleted: true, fileId | path }
Upload — Input Source modes
Mode Behavior
payload (default) Reads from msg.payload (Buffer or stream). msg.filePath is ignored.
file Reads from the configured File Path (or msg.filePath). msg.payload is ignored.
Download — Output Target modes
Mode Behavior
payload (default) msg.payload is the readable stream returned by the provider.
file Streams the response directly to the local filesystem. msg.payload becomes { filePath, fileId }; msg.filePath is also set. Set Overwrite to allow replacing existing files.

File modes touch the local filesystem at runtime and may not work across environments (Docker, cloud). Ensure the Node-RED process can read/write the selected paths.

Inputs

All inputs may be set on the node and overridden via msg:

Property Description
msg.operation overrides node operation (upload, download, list, delete)
msg.payload upload body when Input Source is payload (Buffer or stream)
msg.filename upload filename (default: timestamp)
msg.folderId Google Drive folder ID
msg.path OneDrive path, e.g. Documents/file.txt
msg.mimeType upload MIME type (default: application/octet-stream)
msg.fileId target file ID for download / delete
msg.filePath local source path for upload when Input Source is file
msg.outputFilePath local destination path for download when Output Target is file
Provider constraints
  • Google Drive does not support path. Use folderId.
  • OneDrive upload requires path.
Errors

All errors are normalized to { code, message } and surfaced via node.error() and the status badge. Codes:

Code Meaning
INVALID_INPUT Required input missing or empty
INVALID_OPERATION Operation is not one of the four supported
UNSUPPORTED_INPUT Input not supported for this provider (e.g. path on Google)
MISSING_CONFIG drive-config not linked
PROVIDER_NOT_INITIALIZED Config node failed to initialize the provider
NOT_FOUND API returned 404
UNAUTHORIZED API returned 401 / token refresh failed
FORBIDDEN API returned 403
FILE_EXISTS Local destination file exists and Overwrite is off
LOCAL_IO_ERROR Local filesystem read/write failure
MISSING_ENV_VAR A ${VAR_NAME} reference in config has no matching environment variable
PROVIDER_ERROR Other API failure

Raw provider errors are not propagated.


Node status

Color Meaning
Yellow In progress (shows operation name)
Green Success (ok)
Red Error (shows error code)

OAuth2 Bootstrap

These nodes use OAuth2 with a refresh token. Obtain it externally:

  • Google DriveOAuth2 Playground with scope https://www.googleapis.com/auth/drive
  • OneDrive — Azure app registration with scope Files.ReadWrite

Paste the refresh token directly into the config node. The nodes do not implement a UI for the initial OAuth flow.


Design

  • One unified node, one operation per message
  • Config node as single source of truth for credentials
  • msg.* overrides always win over node config
  • Streams over buffering — download returns a stream, not a Buffer
  • Provider-specific logic lives behind a uniform { upload, download, list, delete } interface
  • Errors are normalized to { code, message } — no raw provider errors leak
  • Manual OAuth bootstrap — no hidden auth flows

License

Apache-2.0

Keywords