@science-corporation/synapse 2.3.0 → 2.3.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/postinstall.sh +185 -185
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@science-corporation/synapse",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Client library and CLI for the Synapse API",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -1,185 +1,185 @@
1
- #!/bin/bash
2
-
3
- # Platform detection
4
- IS_WINDOWS=false
5
- if [ "$OS" = "Windows_NT" ] || [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "cygwin" ]; then
6
- IS_WINDOWS=true
7
- fi
8
-
9
- # If running on Windows, ensure we're using bash
10
- if [ "$IS_WINDOWS" = true ]; then
11
- if ! command -v bash >/dev/null 2>&1; then
12
- echo "Error: bash is required to run this script on Windows"
13
- exit 1
14
- fi
15
- fi
16
-
17
- echo "Postinstall - downloading synapse-api"
18
-
19
- # If synapse-api directory already exists, skip download
20
- if [ -d "synapse-api" ]; then
21
- echo " - synapse-api directory already exists, skipping download"
22
- exit 0
23
- fi
24
-
25
- # If we have git, try to update the submodule
26
- HAS_GIT=false
27
- if command -v git >/dev/null 2>&1 && git rev-parse --git-dir >/dev/null 2>&1; then
28
- HAS_GIT=true
29
- echo " - Git detected, attempting to update submodule..."
30
-
31
- if git submodule update --init synapse-api; then
32
- echo " - Successfully updated synapse-api submodule"
33
- exit 0
34
- else
35
- echo " - Failed to update submodule, falling back to download..."
36
- fi
37
- fi
38
-
39
- # Else, fallback to downloading from github
40
- echo "Downloading synapse-api..."
41
-
42
- # Resolve which synapse-typescript ref to ask the GitHub API about, in order
43
- # of decreasing fidelity:
44
- # 1. git HEAD when there's a real working tree (most accurate).
45
- # 2. The SHA in $npm_package_resolved — npm exports this during install
46
- # lifecycle scripts as `git+ssh://...#<sha>`. This is the one that
47
- # makes `npm install git://...#<sha>` actually work, since during
48
- # pacote's prepare phase the .git dir has been moved away and the
49
- # package.json gitHead field has not yet been injected.
50
- # 3. package.json#gitHead — npm writes this after prepare completes, so
51
- # it's available for downstream consumers reading an already-installed
52
- # package, just not during the prepare phase itself.
53
- # 4. v$version tag, as a last resort for vanilla tarball installs after a
54
- # release has tagged the version.
55
- REF_LIB=""
56
- if [ "$HAS_GIT" = true ]; then
57
- REF_LIB=$(git rev-parse HEAD)
58
- fi
59
-
60
- if [ -z "$REF_LIB" ] && [ -n "$npm_package_resolved" ]; then
61
- # Strip everything up to and including the last '#' to get the SHA.
62
- CANDIDATE="${npm_package_resolved##*#}"
63
- # Only accept if it looks like a SHA (40 hex chars). Anything else is
64
- # probably a URL with no fragment, which would leave the var untouched.
65
- if [ "${#CANDIDATE}" = 40 ] && [ -z "${CANDIDATE//[0-9a-f]/}" ]; then
66
- REF_LIB="$CANDIDATE"
67
- echo " - Using npm_package_resolved SHA for ref lookup"
68
- fi
69
- fi
70
-
71
- if [ -z "$REF_LIB" ]; then
72
- REF_LIB=$(node -e "const p=require('./package.json'); if (p.gitHead) process.stdout.write(p.gitHead);" 2>/dev/null)
73
- if [ -n "$REF_LIB" ]; then
74
- echo " - Using package.json gitHead for ref lookup"
75
- fi
76
- fi
77
-
78
- if [ -z "$REF_LIB" ]; then
79
- PKG_VERSION=$(node -p "require('./package.json').version")
80
- if [ -z "$PKG_VERSION" ]; then
81
- echo " - Failed to get version from package.json"
82
- exit 1
83
- fi
84
- REF_LIB=v$PKG_VERSION
85
- fi
86
-
87
- echo "- Looking up synapse-api ref for synapse-typescript ref $REF_LIB"
88
-
89
- CURL_OPTS=()
90
- CURL_OPTS+=(-H "Accept: application/vnd.github+json")
91
- CURL_OPTS+=(-H "X-GitHub-Api-Version: 2022-11-28")
92
- if [ -n "$SCIENCE_CORPORATION_SYNAPSE_TOKEN" ]; then
93
- echo " - Using GitHub token for authentication"
94
- CURL_OPTS+=(-H "Authorization: Bearer $SCIENCE_CORPORATION_SYNAPSE_TOKEN")
95
- fi
96
-
97
- fetch_synapse_api_sha() {
98
- local use_auth="$1"
99
- local opts=(-H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28")
100
- if [ "$use_auth" = "true" ] && [ -n "$SCIENCE_CORPORATION_SYNAPSE_TOKEN" ]; then
101
- opts+=(-H "Authorization: Bearer $SCIENCE_CORPORATION_SYNAPSE_TOKEN")
102
- fi
103
- curl -s "${opts[@]}" "https://api.github.com/repos/sciencecorp/synapse-typescript/contents/synapse-api?ref=$REF_LIB"
104
- }
105
-
106
- echo " - Fetching synapse-api submodule info..."
107
- CURL_RESULT=$(fetch_synapse_api_sha "true")
108
-
109
- # Check for auth failure and retry without auth
110
- if echo "$CURL_RESULT" | grep -q '"Bad credentials"'; then
111
- echo " - Auth failed, retrying without authentication..."
112
- CURL_RESULT=$(fetch_synapse_api_sha "false")
113
- fi
114
-
115
- if [ -z "$CURL_RESULT" ]; then
116
- echo " - Failed to fetch from GitHub API"
117
- exit 1
118
- fi
119
-
120
- echo " - Parsing SHA from response..."
121
- GREP_RESULT=$(echo "$CURL_RESULT" | grep -o '"sha":\s*"[^"]*"')
122
- if [ -z "$GREP_RESULT" ]; then
123
- echo " - Failed to find SHA in API response"
124
- echo " - API response: $CURL_RESULT"
125
- exit 1
126
- fi
127
-
128
- REF_API=$(echo "${GREP_RESULT#*:}" | tr -d '[:space:]"')
129
- if [ -z "$REF_API" ]; then
130
- echo " - Failed to parse SHA from API response"
131
- echo " - API response: $CURL_RESULT"
132
- exit 1
133
- fi
134
-
135
- echo "- Found synapse-api ref \"$REF_API\""
136
-
137
- # Create temp directory in a cross-platform way
138
- if [ "$IS_WINDOWS" = true ]; then
139
- # Use a more reliable temp directory path on Windows
140
- TMP_DIR="C:\\Users\\$USERNAME\\AppData\\Local\\Temp\\synapse-api-temp"
141
- mkdir -p "$TMP_DIR"
142
- else
143
- TMP_DIR=$(mktemp -d)
144
- fi
145
-
146
- # Download using curl or fallback to PowerShell on Windows if curl fails
147
- if ! curl -s -L "https://github.com/sciencecorp/synapse-api/archive/${REF_API}.zip" -o "$TMP_DIR/synapse-api.zip"; then
148
- if [ "$IS_WINDOWS" = true ]; then
149
- echo " - Curl failed, attempting download with PowerShell..."
150
- powershell -Command "Invoke-WebRequest -Uri 'https://github.com/sciencecorp/synapse-api/archive/${REF_API}.zip' -OutFile '$TMP_DIR\\synapse-api.zip'"
151
- else
152
- echo " - Failed to download synapse-api"
153
- exit 1
154
- fi
155
- fi
156
-
157
- # Unzip in a cross-platform way
158
- if [ "$IS_WINDOWS" = true ]; then
159
- if ! unzip -q "$TMP_DIR/synapse-api.zip" -d "$TMP_DIR" 2>/dev/null; then
160
- echo " - Unzip failed, attempting with PowerShell..."
161
- powershell -Command "Expand-Archive -Path '$TMP_DIR\\synapse-api.zip' -DestinationPath '$TMP_DIR' -Force"
162
- fi
163
- else
164
- if ! unzip -q "$TMP_DIR/synapse-api.zip" -d "$TMP_DIR"; then
165
- echo " - Failed to unzip synapse-api"
166
- exit 1
167
- fi
168
- fi
169
-
170
- # Create directory and copy files in a cross-platform way
171
- mkdir -p synapse-api
172
- if [ "$IS_WINDOWS" = true ]; then
173
- powershell -Command "Copy-Item -Path \"$TMP_DIR\\synapse-api-${REF_API}\\*\" -Destination \"synapse-api\\\" -Recurse -Force"
174
- else
175
- cp -r "$TMP_DIR/synapse-api-${REF_API}/"* synapse-api/
176
- fi
177
-
178
- # Clean up temp files
179
- rm -rf "$TMP_DIR"
180
-
181
- if [ ! -f "synapse-api/README.md" ] || [ ! -f "synapse-api/COPYRIGHT" ] || [ ! -d "synapse-api/api" ]; then
182
- echo " - Failed to download synapse-api - missing required files"
183
- exit 1
184
- fi
185
- echo " - Successfully downloaded synapse-api ref \"$REF_API\""
1
+ #!/bin/bash
2
+
3
+ # Platform detection
4
+ IS_WINDOWS=false
5
+ if [ "$OS" = "Windows_NT" ] || [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "cygwin" ]; then
6
+ IS_WINDOWS=true
7
+ fi
8
+
9
+ # If running on Windows, ensure we're using bash
10
+ if [ "$IS_WINDOWS" = true ]; then
11
+ if ! command -v bash >/dev/null 2>&1; then
12
+ echo "Error: bash is required to run this script on Windows"
13
+ exit 1
14
+ fi
15
+ fi
16
+
17
+ echo "Postinstall - downloading synapse-api"
18
+
19
+ # If synapse-api directory already exists, skip download
20
+ if [ -d "synapse-api" ]; then
21
+ echo " - synapse-api directory already exists, skipping download"
22
+ exit 0
23
+ fi
24
+
25
+ # If we have git, try to update the submodule
26
+ HAS_GIT=false
27
+ if command -v git >/dev/null 2>&1 && git rev-parse --git-dir >/dev/null 2>&1; then
28
+ HAS_GIT=true
29
+ echo " - Git detected, attempting to update submodule..."
30
+
31
+ if git submodule update --init synapse-api; then
32
+ echo " - Successfully updated synapse-api submodule"
33
+ exit 0
34
+ else
35
+ echo " - Failed to update submodule, falling back to download..."
36
+ fi
37
+ fi
38
+
39
+ # Else, fallback to downloading from github
40
+ echo "Downloading synapse-api..."
41
+
42
+ # Resolve which synapse-typescript ref to ask the GitHub API about, in order
43
+ # of decreasing fidelity:
44
+ # 1. git HEAD when there's a real working tree (most accurate).
45
+ # 2. The SHA in $npm_package_resolved — npm exports this during install
46
+ # lifecycle scripts as `git+ssh://...#<sha>`. This is the one that
47
+ # makes `npm install git://...#<sha>` actually work, since during
48
+ # pacote's prepare phase the .git dir has been moved away and the
49
+ # package.json gitHead field has not yet been injected.
50
+ # 3. package.json#gitHead — npm writes this after prepare completes, so
51
+ # it's available for downstream consumers reading an already-installed
52
+ # package, just not during the prepare phase itself.
53
+ # 4. v$version tag, as a last resort for vanilla tarball installs after a
54
+ # release has tagged the version.
55
+ REF_LIB=""
56
+ if [ "$HAS_GIT" = true ]; then
57
+ REF_LIB=$(git rev-parse HEAD)
58
+ fi
59
+
60
+ if [ -z "$REF_LIB" ] && [ -n "$npm_package_resolved" ]; then
61
+ # Strip everything up to and including the last '#' to get the SHA.
62
+ CANDIDATE="${npm_package_resolved##*#}"
63
+ # Only accept if it looks like a SHA (40 hex chars). Anything else is
64
+ # probably a URL with no fragment, which would leave the var untouched.
65
+ if [ "${#CANDIDATE}" = 40 ] && [ -z "${CANDIDATE//[0-9a-f]/}" ]; then
66
+ REF_LIB="$CANDIDATE"
67
+ echo " - Using npm_package_resolved SHA for ref lookup"
68
+ fi
69
+ fi
70
+
71
+ if [ -z "$REF_LIB" ]; then
72
+ REF_LIB=$(node -e "const p=require('./package.json'); if (p.gitHead) process.stdout.write(p.gitHead);" 2>/dev/null)
73
+ if [ -n "$REF_LIB" ]; then
74
+ echo " - Using package.json gitHead for ref lookup"
75
+ fi
76
+ fi
77
+
78
+ if [ -z "$REF_LIB" ]; then
79
+ PKG_VERSION=$(node -p "require('./package.json').version")
80
+ if [ -z "$PKG_VERSION" ]; then
81
+ echo " - Failed to get version from package.json"
82
+ exit 1
83
+ fi
84
+ REF_LIB=v$PKG_VERSION
85
+ fi
86
+
87
+ echo "- Looking up synapse-api ref for synapse-typescript ref $REF_LIB"
88
+
89
+ CURL_OPTS=()
90
+ CURL_OPTS+=(-H "Accept: application/vnd.github+json")
91
+ CURL_OPTS+=(-H "X-GitHub-Api-Version: 2022-11-28")
92
+ if [ -n "$SCIENCE_CORPORATION_SYNAPSE_TOKEN" ]; then
93
+ echo " - Using GitHub token for authentication"
94
+ CURL_OPTS+=(-H "Authorization: Bearer $SCIENCE_CORPORATION_SYNAPSE_TOKEN")
95
+ fi
96
+
97
+ fetch_synapse_api_sha() {
98
+ local use_auth="$1"
99
+ local opts=(-H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28")
100
+ if [ "$use_auth" = "true" ] && [ -n "$SCIENCE_CORPORATION_SYNAPSE_TOKEN" ]; then
101
+ opts+=(-H "Authorization: Bearer $SCIENCE_CORPORATION_SYNAPSE_TOKEN")
102
+ fi
103
+ curl -s "${opts[@]}" "https://api.github.com/repos/sciencecorp/synapse-typescript/contents/synapse-api?ref=$REF_LIB"
104
+ }
105
+
106
+ echo " - Fetching synapse-api submodule info..."
107
+ CURL_RESULT=$(fetch_synapse_api_sha "true")
108
+
109
+ # Check for auth failure and retry without auth
110
+ if echo "$CURL_RESULT" | grep -q '"Bad credentials"'; then
111
+ echo " - Auth failed, retrying without authentication..."
112
+ CURL_RESULT=$(fetch_synapse_api_sha "false")
113
+ fi
114
+
115
+ if [ -z "$CURL_RESULT" ]; then
116
+ echo " - Failed to fetch from GitHub API"
117
+ exit 1
118
+ fi
119
+
120
+ echo " - Parsing SHA from response..."
121
+ GREP_RESULT=$(echo "$CURL_RESULT" | grep -o '"sha":\s*"[^"]*"')
122
+ if [ -z "$GREP_RESULT" ]; then
123
+ echo " - Failed to find SHA in API response"
124
+ echo " - API response: $CURL_RESULT"
125
+ exit 1
126
+ fi
127
+
128
+ REF_API=$(echo "${GREP_RESULT#*:}" | tr -d '[:space:]"')
129
+ if [ -z "$REF_API" ]; then
130
+ echo " - Failed to parse SHA from API response"
131
+ echo " - API response: $CURL_RESULT"
132
+ exit 1
133
+ fi
134
+
135
+ echo "- Found synapse-api ref \"$REF_API\""
136
+
137
+ # Create temp directory in a cross-platform way
138
+ if [ "$IS_WINDOWS" = true ]; then
139
+ # Use a more reliable temp directory path on Windows
140
+ TMP_DIR="C:\\Users\\$USERNAME\\AppData\\Local\\Temp\\synapse-api-temp"
141
+ mkdir -p "$TMP_DIR"
142
+ else
143
+ TMP_DIR=$(mktemp -d)
144
+ fi
145
+
146
+ # Download using curl or fallback to PowerShell on Windows if curl fails
147
+ if ! curl -s -L "https://github.com/sciencecorp/synapse-api/archive/${REF_API}.zip" -o "$TMP_DIR/synapse-api.zip"; then
148
+ if [ "$IS_WINDOWS" = true ]; then
149
+ echo " - Curl failed, attempting download with PowerShell..."
150
+ powershell -Command "Invoke-WebRequest -Uri 'https://github.com/sciencecorp/synapse-api/archive/${REF_API}.zip' -OutFile '$TMP_DIR\\synapse-api.zip'"
151
+ else
152
+ echo " - Failed to download synapse-api"
153
+ exit 1
154
+ fi
155
+ fi
156
+
157
+ # Unzip in a cross-platform way
158
+ if [ "$IS_WINDOWS" = true ]; then
159
+ if ! unzip -q "$TMP_DIR/synapse-api.zip" -d "$TMP_DIR" 2>/dev/null; then
160
+ echo " - Unzip failed, attempting with PowerShell..."
161
+ powershell -Command "Expand-Archive -Path '$TMP_DIR\\synapse-api.zip' -DestinationPath '$TMP_DIR' -Force"
162
+ fi
163
+ else
164
+ if ! unzip -q "$TMP_DIR/synapse-api.zip" -d "$TMP_DIR"; then
165
+ echo " - Failed to unzip synapse-api"
166
+ exit 1
167
+ fi
168
+ fi
169
+
170
+ # Create directory and copy files in a cross-platform way
171
+ mkdir -p synapse-api
172
+ if [ "$IS_WINDOWS" = true ]; then
173
+ powershell -Command "Copy-Item -Path \"$TMP_DIR\\synapse-api-${REF_API}\\*\" -Destination \"synapse-api\\\" -Recurse -Force"
174
+ else
175
+ cp -r "$TMP_DIR/synapse-api-${REF_API}/"* synapse-api/
176
+ fi
177
+
178
+ # Clean up temp files
179
+ rm -rf "$TMP_DIR"
180
+
181
+ if [ ! -f "synapse-api/README.md" ] || [ ! -f "synapse-api/COPYRIGHT" ] || [ ! -d "synapse-api/api" ]; then
182
+ echo " - Failed to download synapse-api - missing required files"
183
+ exit 1
184
+ fi
185
+ echo " - Successfully downloaded synapse-api ref \"$REF_API\""