fostrom 0.0.16 → 0.0.18
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 +1 -67
- package/dl-agent.sh +26 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,70 +4,4 @@
|
|
|
4
4
|
|
|
5
5
|
The Fostrom Device SDK for JavaScript works in Node.js and Bun, on Linux and macOS, and helps you quickly integrate, start monitoring, and controlling your IoT devices in just a few lines of code.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
import Fostrom from 'fostrom';
|
|
11
|
-
|
|
12
|
-
const fostrom = new Fostrom({
|
|
13
|
-
fleet_id: "<fleet-id>",
|
|
14
|
-
device_id: "<device-id>",
|
|
15
|
-
device_secret: "<device-secret>",
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
// Setup the on_mail handler, to process incoming mail.
|
|
19
|
-
fostrom.onMail = async (mail) => {
|
|
20
|
-
const {id, name, payload, mailbox_size} = mail
|
|
21
|
-
console.debug(`Received Mail (${mailbox_size}): ${name} ${id}`)
|
|
22
|
-
|
|
23
|
-
// You need to call `mail.ack()` to acknowledge the mail.
|
|
24
|
-
// Other options are: `mail.reject()` and `mail.requeue()`
|
|
25
|
-
// Note that if your function throws an error, the SDK will auto-reject the mail.
|
|
26
|
-
await mail.ack()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function main() {
|
|
30
|
-
await fostrom.start()
|
|
31
|
-
|
|
32
|
-
// Send a message to Fostrom (payload can be null if schema has no payload)
|
|
33
|
-
await fostrom.sendMsg("<packet-schema-name>", { /* ...payload */ })
|
|
34
|
-
|
|
35
|
-
// Send a datapoint to Fostrom
|
|
36
|
-
await fostrom.sendDatapoint("<packet-schema-name>", { /* ...payload */ })
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
main()
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
> Requires Node.js 22.12+ or Bun 1.2+
|
|
43
|
-
|
|
44
|
-
You can load the SDK via either syntax:
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
import Fostrom from 'fostrom'
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
const { default: Fostrom } = require('fostrom')
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## A Note on BigInts
|
|
55
|
-
|
|
56
|
-
Fostrom's Packet Schemas support defining `u64` and `i64` integers. However, JavaScript's `Number` type is limited to `2^53 - 1`. To rectify this issue, we use the `bigint` type and handle JSON encoding and decoding automatically.
|
|
57
|
-
|
|
58
|
-
Note that there's a caveat here. When Fostrom delivers a message to the SDK containing a `u64` or `i64` number, it will convert to the `Number` type if it is smaller than `2^53 - 1`, and convert to `bigint` if it is larger. This is because the SDK does not know if the field is a `u64` or `i64` type when converting. So for those fields you will need to check whether the type is `bigint` or not.
|
|
59
|
-
|
|
60
|
-
## A Note on the Device Agent
|
|
61
|
-
|
|
62
|
-
The Fostrom Device SDK downloads and runs the Fostrom Device Agent in the background. The Agent is downloaded when the package is installed through `npm`. The Device Agent starts when `fostrom.start()` is called and handles communication with the Fostrom platform.
|
|
63
|
-
|
|
64
|
-
By default, the agent remains running in the background for fast reconnections. The SDK also installs a process exit handler; `fostrom.shutdown()` is called automatically on process exit, and if `stopAgentOnExit` is set to true in the config, the agent is stopped as well.
|
|
65
|
-
|
|
66
|
-
## Logging
|
|
67
|
-
|
|
68
|
-
By default, the SDK logs connection and handler messages to the console. Set
|
|
69
|
-
`log: false` in the constructor config to silence SDK logs. Levels used:
|
|
70
|
-
|
|
71
|
-
- `console.info` for successful connection events
|
|
72
|
-
- `console.warn` for reconnection attempts
|
|
73
|
-
- `console.error` for unauthorized/critical errors
|
|
7
|
+
[Visit our JavaScript SDK Docs to get started.](https://fostrom.io/docs/sdk/js)
|
package/dl-agent.sh
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
#
|
|
5
5
|
# Usage: ./dl-agent.sh <directory>
|
|
6
6
|
|
|
7
|
-
VERSION="v0.0.
|
|
7
|
+
VERSION="v0.0.16"
|
|
8
8
|
|
|
9
9
|
# CDN URLs in order of preference
|
|
10
10
|
CDN_PRIMARY="https://cdn.fostrom.dev/fostrom-device-agent/$VERSION"
|
|
@@ -29,7 +29,13 @@ download_file() {
|
|
|
29
29
|
if command -v curl >/dev/null 2>&1; then
|
|
30
30
|
curl -fsSL --connect-timeout 10 --max-time 300 "$URL" -o "$OUTPUT" 2>/dev/null
|
|
31
31
|
elif command -v wget >/dev/null 2>&1; then
|
|
32
|
-
|
|
32
|
+
# BusyBox wget often lacks GNU long opts like --tries/--timeout.
|
|
33
|
+
if wget --help 2>&1 | grep -q -- '--tries'; then
|
|
34
|
+
wget -q --timeout=10 --tries=1 -O "$OUTPUT" "$URL" 2>/dev/null
|
|
35
|
+
else
|
|
36
|
+
# BusyBox-compatible fallback (fewer assumptions)
|
|
37
|
+
wget -q -O "$OUTPUT" "$URL" 2>/dev/null
|
|
38
|
+
fi
|
|
33
39
|
else
|
|
34
40
|
die "No download tool found (curl or wget required)"
|
|
35
41
|
fi
|
|
@@ -50,7 +56,9 @@ try_download() {
|
|
|
50
56
|
|
|
51
57
|
create_temp_dir() {
|
|
52
58
|
if command -v mktemp >/dev/null 2>&1; then
|
|
53
|
-
mktemp -d 2>/dev/null
|
|
59
|
+
mktemp -d -t 'fostrom.XXXXXX' 2>/dev/null \
|
|
60
|
+
|| mktemp -d "${TMPDIR:-/tmp}/fostrom.XXXXXX" 2>/dev/null \
|
|
61
|
+
|| mktemp -d 2>/dev/null
|
|
54
62
|
else
|
|
55
63
|
TEMP_DIR="/tmp/fostrom.$$"
|
|
56
64
|
mkdir -p "$TEMP_DIR" || die "Cannot create temporary directory"
|
|
@@ -60,12 +68,20 @@ create_temp_dir() {
|
|
|
60
68
|
|
|
61
69
|
verify_checksum() {
|
|
62
70
|
CHECKSUM_FILE="$1"
|
|
71
|
+
TARGET_FILE="$2"
|
|
72
|
+
|
|
73
|
+
HASH_FILE="$TEMP_DIR/$TARGET_FILE.sha256"
|
|
74
|
+
|
|
75
|
+
awk -v f="$TARGET_FILE" '
|
|
76
|
+
{ name=$2; sub(/^\*/, "", name) }
|
|
77
|
+
name==f { print; found=1 }
|
|
78
|
+
END { exit !found }
|
|
79
|
+
' "$CHECKSUM_FILE" > "$HASH_FILE" || return 1
|
|
63
80
|
|
|
64
|
-
# Try sha256sum (Linux) first, then shasum (macOS)
|
|
65
81
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
66
|
-
sha256sum -c
|
|
82
|
+
sha256sum -c "$HASH_FILE" >/dev/null 2>&1
|
|
67
83
|
elif command -v shasum >/dev/null 2>&1; then
|
|
68
|
-
shasum -a 256 -c
|
|
84
|
+
shasum -a 256 -c "$HASH_FILE" >/dev/null 2>&1
|
|
69
85
|
else
|
|
70
86
|
printf "Warning: No checksum verification tool found, skipping verification\n" >&2
|
|
71
87
|
return 0
|
|
@@ -94,7 +110,7 @@ download_and_verify() {
|
|
|
94
110
|
|
|
95
111
|
# Verify checksum
|
|
96
112
|
cd "$TEMP_DIR"
|
|
97
|
-
if ! verify_checksum "fostrom-device-agent.sha256"; then
|
|
113
|
+
if ! verify_checksum "fostrom-device-agent.sha256" "$FILENAME"; then
|
|
98
114
|
die "Checksum verification failed"
|
|
99
115
|
fi
|
|
100
116
|
cd - >/dev/null
|
|
@@ -131,13 +147,13 @@ main() {
|
|
|
131
147
|
case "$ARCH" in
|
|
132
148
|
x86_64|amd64) ARCH="amd64" ;;
|
|
133
149
|
aarch64|arm64) ARCH="arm64" ;;
|
|
134
|
-
armv6l) ARCH="
|
|
150
|
+
armv6l) ARCH="armv6hf" ;;
|
|
135
151
|
riscv64) ARCH="riscv64" ;;
|
|
136
152
|
*) die "Unsupported architecture: $ARCH" ;;
|
|
137
153
|
esac
|
|
138
154
|
;;
|
|
139
155
|
Darwin*)
|
|
140
|
-
OS="
|
|
156
|
+
OS="macos"
|
|
141
157
|
case "$ARCH" in
|
|
142
158
|
x86_64|amd64) ARCH="amd64" ;;
|
|
143
159
|
aarch64|arm64) ARCH="arm64" ;;
|
|
@@ -159,7 +175,7 @@ main() {
|
|
|
159
175
|
download_and_verify "$FILENAME" "$LOCATION"
|
|
160
176
|
|
|
161
177
|
# Remove quarantine on macOS
|
|
162
|
-
if [ "$OS" = "
|
|
178
|
+
if [ "$OS" = "macos" ]; then
|
|
163
179
|
xattr -r -d com.apple.quarantine "$LOCATION/$FILENAME" 2>/dev/null || true
|
|
164
180
|
fi
|
|
165
181
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fostrom",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Fostrom's Official Device SDK for JS. Fostrom (https://fostrom.io) is an IoT Cloud Platform.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fostrom",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"hardware",
|
|
18
18
|
"raspberry"
|
|
19
19
|
],
|
|
20
|
-
"homepage": "https://
|
|
20
|
+
"homepage": "https://fostrom.io/docs/sdk/js",
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"author": "Fostrom <support@fostrom.io> (https://fostrom.io)",
|
|
23
23
|
"files": [
|