@science-corporation/synapse 2.2.9 → 2.3.0

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/package.json CHANGED
@@ -1,70 +1,70 @@
1
- {
2
- "name": "@science-corporation/synapse",
3
- "version": "2.2.9",
4
- "description": "Client library and CLI for the Synapse API",
5
- "license": "Apache-2.0",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
12
- },
13
- "./browser": {
14
- "types": "./dist/browser.d.ts",
15
- "default": "./dist/browser.js"
16
- }
17
- },
18
- "files": [
19
- "dist",
20
- "scripts",
21
- "src",
22
- "synapse-api"
23
- ],
24
- "scripts": {
25
- "build": "bash ./scripts/build.sh",
26
- "clean": "rimraf dist src/api",
27
- "dist": "npm run generate && npm run build",
28
- "generate": "bash ./scripts/generate.sh",
29
- "lint": "tsc --noEmit && eslint .",
30
- "postinstall": "bash ./scripts/postinstall.sh && npm run dist",
31
- "test": "tsc --noEmit && jest"
32
- },
33
- "repository": {
34
- "type": "git",
35
- "url": "git+https://github.com/sciencecorp/synapse-typescript.git"
36
- },
37
- "author": {
38
- "name": "Science Corporation",
39
- "email": "team@science.xyz"
40
- },
41
- "bugs": {
42
- "url": "https://github.com/sciencecorp/synapse-typescript/issues"
43
- },
44
- "homepage": "https://github.com/sciencecorp/synapse-typescript#readme",
45
- "engines": {
46
- "node": ">=18"
47
- },
48
- "devDependencies": {
49
- "@eslint/compat": "^1.2.6",
50
- "@types/jest": "^29.5.14",
51
- "@typescript-eslint/eslint-plugin": "^8.23.0",
52
- "@typescript-eslint/parser": "^8.23.0",
53
- "eslint": "^9.5.0",
54
- "eslint-import-resolver-typescript": "^3.7.0",
55
- "eslint-plugin-import": "^2.31.0",
56
- "jest": "^29.7.0",
57
- "rimraf": "^5.0.5",
58
- "ts-jest": "^29.2.5",
59
- "typescript": "^5.5.2"
60
- },
61
- "dependencies": {
62
- "@grpc/grpc-js": "^1.10.10",
63
- "@grpc/proto-loader": "^0.7.13",
64
- "google-protobuf": "^3.21.2",
65
- "long": "^5.3.1",
66
- "protobufjs-cli": "^1.1.3",
67
- "tmp": "^0.2.5",
68
- "yargs": "^17.7.2"
69
- }
70
- }
1
+ {
2
+ "name": "@science-corporation/synapse",
3
+ "version": "2.3.0",
4
+ "description": "Client library and CLI for the Synapse API",
5
+ "license": "Apache-2.0",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./browser": {
14
+ "types": "./dist/browser.d.ts",
15
+ "default": "./dist/browser.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "scripts",
21
+ "src",
22
+ "synapse-api"
23
+ ],
24
+ "scripts": {
25
+ "build": "bash ./scripts/build.sh",
26
+ "clean": "rimraf dist src/api",
27
+ "dist": "npm run generate && npm run build",
28
+ "generate": "bash ./scripts/generate.sh",
29
+ "lint": "tsc --noEmit && eslint .",
30
+ "postinstall": "bash ./scripts/postinstall.sh && npm run dist",
31
+ "test": "tsc --noEmit && jest"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/sciencecorp/synapse-typescript.git"
36
+ },
37
+ "author": {
38
+ "name": "Science Corporation",
39
+ "email": "team@science.xyz"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/sciencecorp/synapse-typescript/issues"
43
+ },
44
+ "homepage": "https://github.com/sciencecorp/synapse-typescript#readme",
45
+ "engines": {
46
+ "node": ">=18"
47
+ },
48
+ "devDependencies": {
49
+ "@eslint/compat": "^1.2.6",
50
+ "@types/jest": "^29.5.14",
51
+ "@typescript-eslint/eslint-plugin": "^8.23.0",
52
+ "@typescript-eslint/parser": "^8.23.0",
53
+ "eslint": "^9.5.0",
54
+ "eslint-import-resolver-typescript": "^3.7.0",
55
+ "eslint-plugin-import": "^2.31.0",
56
+ "jest": "^29.7.0",
57
+ "rimraf": "^5.0.5",
58
+ "ts-jest": "^29.2.5",
59
+ "typescript": "^5.5.2"
60
+ },
61
+ "dependencies": {
62
+ "@grpc/grpc-js": "^1.10.10",
63
+ "@grpc/proto-loader": "^0.7.13",
64
+ "google-protobuf": "^3.21.2",
65
+ "long": "^5.3.1",
66
+ "protobufjs-cli": "^1.1.3",
67
+ "tmp": "^0.2.5",
68
+ "yargs": "^17.7.2"
69
+ }
70
+ }
@@ -1,151 +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
- if [ "$HAS_GIT" = true ]; then
43
- REF_LIB=$(git rev-parse HEAD)
44
- else
45
- REF_LIB=$(node -p "require('./package.json').version")
46
- if [ -z "$REF_LIB" ]; then
47
- echo " - Failed to get version from package.json"
48
- exit 1
49
- fi
50
- REF_LIB=v$REF_LIB
51
- fi
52
-
53
- echo "- Looking up synapse-api ref for synapse-typescript ref $REF_LIB"
54
-
55
- CURL_OPTS=()
56
- CURL_OPTS+=(-H "Accept: application/vnd.github+json")
57
- CURL_OPTS+=(-H "X-GitHub-Api-Version: 2022-11-28")
58
- if [ -n "$SCIENCE_CORPORATION_SYNAPSE_TOKEN" ]; then
59
- echo " - Using GitHub token for authentication"
60
- CURL_OPTS+=(-H "Authorization: Bearer $SCIENCE_CORPORATION_SYNAPSE_TOKEN")
61
- fi
62
-
63
- fetch_synapse_api_sha() {
64
- local use_auth="$1"
65
- local opts=(-H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28")
66
- if [ "$use_auth" = "true" ] && [ -n "$SCIENCE_CORPORATION_SYNAPSE_TOKEN" ]; then
67
- opts+=(-H "Authorization: Bearer $SCIENCE_CORPORATION_SYNAPSE_TOKEN")
68
- fi
69
- curl -s "${opts[@]}" "https://api.github.com/repos/sciencecorp/synapse-typescript/contents/synapse-api?ref=$REF_LIB"
70
- }
71
-
72
- echo " - Fetching synapse-api submodule info..."
73
- CURL_RESULT=$(fetch_synapse_api_sha "true")
74
-
75
- # Check for auth failure and retry without auth
76
- if echo "$CURL_RESULT" | grep -q '"Bad credentials"'; then
77
- echo " - Auth failed, retrying without authentication..."
78
- CURL_RESULT=$(fetch_synapse_api_sha "false")
79
- fi
80
-
81
- if [ -z "$CURL_RESULT" ]; then
82
- echo " - Failed to fetch from GitHub API"
83
- exit 1
84
- fi
85
-
86
- echo " - Parsing SHA from response..."
87
- GREP_RESULT=$(echo "$CURL_RESULT" | grep -o '"sha":\s*"[^"]*"')
88
- if [ -z "$GREP_RESULT" ]; then
89
- echo " - Failed to find SHA in API response"
90
- echo " - API response: $CURL_RESULT"
91
- exit 1
92
- fi
93
-
94
- REF_API=$(echo "${GREP_RESULT#*:}" | tr -d '[:space:]"')
95
- if [ -z "$REF_API" ]; then
96
- echo " - Failed to parse SHA from API response"
97
- echo " - API response: $CURL_RESULT"
98
- exit 1
99
- fi
100
-
101
- echo "- Found synapse-api ref \"$REF_API\""
102
-
103
- # Create temp directory in a cross-platform way
104
- if [ "$IS_WINDOWS" = true ]; then
105
- # Use a more reliable temp directory path on Windows
106
- TMP_DIR="C:\\Users\\$USERNAME\\AppData\\Local\\Temp\\synapse-api-temp"
107
- mkdir -p "$TMP_DIR"
108
- else
109
- TMP_DIR=$(mktemp -d)
110
- fi
111
-
112
- # Download using curl or fallback to PowerShell on Windows if curl fails
113
- if ! curl -s -L "https://github.com/sciencecorp/synapse-api/archive/${REF_API}.zip" -o "$TMP_DIR/synapse-api.zip"; then
114
- if [ "$IS_WINDOWS" = true ]; then
115
- echo " - Curl failed, attempting download with PowerShell..."
116
- powershell -Command "Invoke-WebRequest -Uri 'https://github.com/sciencecorp/synapse-api/archive/${REF_API}.zip' -OutFile '$TMP_DIR\\synapse-api.zip'"
117
- else
118
- echo " - Failed to download synapse-api"
119
- exit 1
120
- fi
121
- fi
122
-
123
- # Unzip in a cross-platform way
124
- if [ "$IS_WINDOWS" = true ]; then
125
- if ! unzip -q "$TMP_DIR/synapse-api.zip" -d "$TMP_DIR" 2>/dev/null; then
126
- echo " - Unzip failed, attempting with PowerShell..."
127
- powershell -Command "Expand-Archive -Path '$TMP_DIR\\synapse-api.zip' -DestinationPath '$TMP_DIR' -Force"
128
- fi
129
- else
130
- if ! unzip -q "$TMP_DIR/synapse-api.zip" -d "$TMP_DIR"; then
131
- echo " - Failed to unzip synapse-api"
132
- exit 1
133
- fi
134
- fi
135
-
136
- # Create directory and copy files in a cross-platform way
137
- mkdir -p synapse-api
138
- if [ "$IS_WINDOWS" = true ]; then
139
- powershell -Command "Copy-Item -Path \"$TMP_DIR\\synapse-api-${REF_API}\\*\" -Destination \"synapse-api\\\" -Recurse -Force"
140
- else
141
- cp -r "$TMP_DIR/synapse-api-${REF_API}/"* synapse-api/
142
- fi
143
-
144
- # Clean up temp files
145
- rm -rf "$TMP_DIR"
146
-
147
- if [ ! -f "synapse-api/README.md" ] || [ ! -f "synapse-api/COPYRIGHT" ] || [ ! -d "synapse-api/api" ]; then
148
- echo " - Failed to download synapse-api - missing required files"
149
- exit 1
150
- fi
151
- 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\""