@assinafy/cli 1.0.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/install.ps1 ADDED
@@ -0,0 +1,124 @@
1
+ param(
2
+ [string]$Version = ""
3
+ )
4
+
5
+ $ErrorActionPreference = "Stop"
6
+
7
+ function Fail([string]$Message) {
8
+ Write-Error $Message
9
+ exit 1
10
+ }
11
+
12
+ function Info([string]$Message) {
13
+ Write-Host "==> $Message"
14
+ }
15
+
16
+ function Success([string]$Message) {
17
+ Write-Host "Success: $Message"
18
+ }
19
+
20
+ function Require-Command([string]$Command) {
21
+ if (-not (Get-Command $Command -ErrorAction SilentlyContinue)) {
22
+ Fail "Required command not found: $Command"
23
+ }
24
+ }
25
+
26
+ function Add-UserPath([string]$Directory) {
27
+ $current = [Environment]::GetEnvironmentVariable("Path", "User")
28
+ if ([string]::IsNullOrWhiteSpace($current)) {
29
+ [Environment]::SetEnvironmentVariable("Path", $Directory, "User")
30
+ $env:Path = "$Directory;$env:Path"
31
+ return
32
+ }
33
+
34
+ $entries = $current -split ";"
35
+ if ($entries -contains $Directory) {
36
+ return
37
+ }
38
+
39
+ [Environment]::SetEnvironmentVariable("Path", "$current;$Directory", "User")
40
+ $env:Path = "$Directory;$env:Path"
41
+ }
42
+
43
+ Require-Command "node"
44
+ Require-Command "tar"
45
+
46
+ $nodeMajor = [int](& node -p "Number(process.versions.node.split('.')[0])")
47
+ if ($nodeMajor -lt 18) {
48
+ Fail "Node.js 18+ is required. Found: $(& node --version)"
49
+ }
50
+
51
+ $archName = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant()
52
+ switch ($archName) {
53
+ "x64" { $arch = "x64" }
54
+ "arm64" { $arch = "arm64" }
55
+ default { Fail "Unsupported CPU architecture: $archName" }
56
+ }
57
+
58
+ $target = "windows-$arch"
59
+ $githubBase = $env:GITHUB_BASE
60
+ if ([string]::IsNullOrWhiteSpace($githubBase)) {
61
+ $githubBase = "https://github.com"
62
+ }
63
+ if (-not $githubBase.StartsWith("https://")) {
64
+ Fail "GITHUB_BASE must start with https://"
65
+ }
66
+
67
+ $repo = $env:ASSINAFY_REPO
68
+ if ([string]::IsNullOrWhiteSpace($repo)) {
69
+ $repo = "assinafy/assinafy-cli"
70
+ }
71
+
72
+ $installDir = $env:ASSINAFY_INSTALL
73
+ if ([string]::IsNullOrWhiteSpace($installDir)) {
74
+ $installDir = Join-Path $HOME ".assinafy"
75
+ }
76
+ $binDir = Join-Path $installDir "bin"
77
+ $exe = Join-Path $binDir "assinafy.cmd"
78
+
79
+ $baseUrl = "$($githubBase.TrimEnd('/'))/$repo"
80
+ $cleanVersion = $Version.TrimStart("v")
81
+ if ([string]::IsNullOrWhiteSpace($cleanVersion)) {
82
+ $url = "$baseUrl/releases/latest/download/assinafy-$target.tar.gz"
83
+ } elseif ($cleanVersion -match "^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$") {
84
+ $url = "$baseUrl/releases/download/v$cleanVersion/assinafy-$target.tar.gz"
85
+ } else {
86
+ Fail "Version must be a semantic version, for example v1.0.0"
87
+ }
88
+
89
+ $tmpDir = Join-Path ([IO.Path]::GetTempPath()) "assinafy-$([Guid]::NewGuid())"
90
+ $archive = Join-Path $tmpDir "assinafy.tar.gz"
91
+ $extractDir = Join-Path $tmpDir "extract"
92
+
93
+ try {
94
+ New-Item -ItemType Directory -Path $binDir, $extractDir -Force | Out-Null
95
+ Info "Downloading Assinafy CLI for $target"
96
+ Invoke-WebRequest -Uri $url -OutFile $archive -UseBasicParsing
97
+ tar -xzf $archive -C $extractDir
98
+
99
+ $cmdSource = Join-Path $extractDir "assinafy.cmd"
100
+ $cjsSource = Join-Path $extractDir "assinafy.cjs"
101
+ if (-not (Test-Path $cmdSource) -or -not (Test-Path $cjsSource)) {
102
+ Fail "Release archive did not contain the Windows Assinafy executable"
103
+ }
104
+
105
+ Copy-Item $cmdSource $exe -Force
106
+ Copy-Item $cjsSource (Join-Path $binDir "assinafy.cjs") -Force
107
+ foreach ($file in @("README.md", "LICENSE", "VERSION")) {
108
+ $source = Join-Path $extractDir $file
109
+ if (Test-Path $source) {
110
+ Copy-Item $source (Join-Path $installDir $file) -Force
111
+ }
112
+ }
113
+
114
+ Add-UserPath $binDir
115
+ $installedVersion = & $exe --version
116
+ if ([string]::IsNullOrWhiteSpace($installedVersion)) {
117
+ Fail "Installed executable did not run. Confirm Node.js 18+ is available on PATH."
118
+ }
119
+
120
+ Success "Installed $installedVersion to $exe"
121
+ Write-Host "Open a new terminal if assinafy is not immediately available on PATH."
122
+ } finally {
123
+ Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
124
+ }
package/install.sh ADDED
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ main() {
5
+ local requested_version="${1:-}"
6
+ local github_base="${GITHUB_BASE:-https://github.com}"
7
+ local repo="${ASSINAFY_REPO:-assinafy/assinafy-cli}"
8
+ local install_dir="${ASSINAFY_INSTALL:-$HOME/.assinafy}"
9
+ local bin_dir="$install_dir/bin"
10
+ local tmp_dir
11
+ tmp_dir="$(mktemp -d)"
12
+ trap 'rm -rf "$tmp_dir"' EXIT
13
+
14
+ setup_colors
15
+ check_prerequisites
16
+ validate_github_base "$github_base"
17
+
18
+ local target archive_url archive extract_dir executable installed_version
19
+ target="$(detect_target)"
20
+ archive_url="$(release_url "$github_base" "$repo" "$requested_version" "$target")"
21
+ archive="$tmp_dir/assinafy.tar.gz"
22
+ extract_dir="$tmp_dir/extract"
23
+ executable="$bin_dir/assinafy"
24
+
25
+ info "Downloading Assinafy CLI for $target"
26
+ curl -fsSL "$archive_url" -o "$archive"
27
+
28
+ mkdir -p "$extract_dir" "$bin_dir" "$install_dir"
29
+ tar -xzf "$archive" -C "$extract_dir"
30
+
31
+ if [ ! -f "$extract_dir/assinafy" ]; then
32
+ fail "Release archive did not contain the assinafy executable"
33
+ fi
34
+
35
+ cp "$extract_dir/assinafy" "$executable"
36
+ chmod 755 "$executable"
37
+
38
+ if [ -f "$extract_dir/README.md" ]; then cp "$extract_dir/README.md" "$install_dir/README.md"; fi
39
+ if [ -f "$extract_dir/LICENSE" ]; then cp "$extract_dir/LICENSE" "$install_dir/LICENSE"; fi
40
+ if [ -f "$extract_dir/VERSION" ]; then cp "$extract_dir/VERSION" "$install_dir/VERSION"; fi
41
+
42
+ if command -v xattr >/dev/null 2>&1; then
43
+ xattr -d com.apple.quarantine "$executable" >/dev/null 2>&1 || true
44
+ fi
45
+
46
+ installed_version="$("$executable" --version 2>/dev/null || true)"
47
+ if [ -z "$installed_version" ]; then
48
+ fail "Installed executable did not run. Confirm Node.js 18+ is available on PATH."
49
+ fi
50
+
51
+ ensure_path "$bin_dir"
52
+ success "Installed $installed_version to $executable"
53
+
54
+ if ! path_has "$bin_dir"; then
55
+ warn "$bin_dir is not on PATH in this shell. Open a new shell or run:"
56
+ printf ' export PATH="%s:$PATH"\n' "$bin_dir"
57
+ fi
58
+ }
59
+
60
+ setup_colors() {
61
+ if [ -t 1 ]; then
62
+ red="$(printf '\033[31m')"
63
+ green="$(printf '\033[32m')"
64
+ yellow="$(printf '\033[33m')"
65
+ blue="$(printf '\033[34m')"
66
+ bold="$(printf '\033[1m')"
67
+ reset="$(printf '\033[0m')"
68
+ else
69
+ red=""
70
+ green=""
71
+ yellow=""
72
+ blue=""
73
+ bold=""
74
+ reset=""
75
+ fi
76
+ }
77
+
78
+ info() {
79
+ printf '%s==>%s %s\n' "$blue" "$reset" "$1"
80
+ }
81
+
82
+ warn() {
83
+ printf '%sWarning:%s %s\n' "$yellow" "$reset" "$1"
84
+ }
85
+
86
+ success() {
87
+ printf '%sSuccess:%s %s\n' "$green" "$reset" "$1"
88
+ }
89
+
90
+ fail() {
91
+ printf '%sError:%s %s\n' "$red" "$reset" "$1" >&2
92
+ exit 1
93
+ }
94
+
95
+ need_cmd() {
96
+ if ! command -v "$1" >/dev/null 2>&1; then
97
+ fail "Required command not found: $1"
98
+ fi
99
+ }
100
+
101
+ check_prerequisites() {
102
+ need_cmd curl
103
+ need_cmd tar
104
+ need_cmd node
105
+
106
+ local node_major
107
+ node_major="$(node -p "Number(process.versions.node.split('.')[0])" 2>/dev/null || echo 0)"
108
+ if [ "$node_major" -lt 18 ]; then
109
+ fail "Node.js 18+ is required. Found: $(node --version 2>/dev/null || echo unknown)"
110
+ fi
111
+ }
112
+
113
+ validate_github_base() {
114
+ case "$1" in
115
+ https://*) ;;
116
+ *) fail "GITHUB_BASE must start with https://" ;;
117
+ esac
118
+ }
119
+
120
+ detect_target() {
121
+ local os arch
122
+ case "$(uname -s)" in
123
+ Darwin) os="darwin" ;;
124
+ Linux) os="linux" ;;
125
+ *) fail "Unsupported operating system: $(uname -s)" ;;
126
+ esac
127
+
128
+ case "$(uname -m)" in
129
+ arm64 | aarch64) arch="arm64" ;;
130
+ x86_64 | amd64) arch="x64" ;;
131
+ *) fail "Unsupported CPU architecture: $(uname -m)" ;;
132
+ esac
133
+
134
+ printf '%s-%s' "$os" "$arch"
135
+ }
136
+
137
+ release_url() {
138
+ local github_base="$1"
139
+ local repo="$2"
140
+ local requested_version="$3"
141
+ local target="$4"
142
+ local base
143
+ base="${github_base%/}/${repo}"
144
+
145
+ if [ -z "$requested_version" ]; then
146
+ printf '%s/releases/latest/download/assinafy-%s.tar.gz' "$base" "$target"
147
+ return
148
+ fi
149
+
150
+ requested_version="${requested_version#v}"
151
+ if ! [[ "$requested_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
152
+ fail "Version must be a semantic version, for example v1.0.0"
153
+ fi
154
+
155
+ printf '%s/releases/download/v%s/assinafy-%s.tar.gz' "$base" "$requested_version" "$target"
156
+ }
157
+
158
+ path_has() {
159
+ case ":${PATH:-}:" in
160
+ *":$1:"*) return 0 ;;
161
+ *) return 1 ;;
162
+ esac
163
+ }
164
+
165
+ append_once() {
166
+ local file="$1"
167
+ local text="$2"
168
+ mkdir -p "$(dirname "$file")"
169
+ touch "$file"
170
+ if ! grep -F "$text" "$file" >/dev/null 2>&1; then
171
+ printf '\n%s\n' "$text" >>"$file"
172
+ fi
173
+ }
174
+
175
+ ensure_path() {
176
+ local bin_dir="$1"
177
+ if [ "${ASSINAFY_NO_PATH_UPDATE:-}" = "1" ] || path_has "$bin_dir"; then
178
+ return
179
+ fi
180
+
181
+ case "$(basename "${SHELL:-}")" in
182
+ fish)
183
+ append_once "$HOME/.config/fish/config.fish" "fish_add_path \"$bin_dir\" # Assinafy CLI"
184
+ ;;
185
+ zsh)
186
+ append_once "$HOME/.zshrc" "export PATH=\"$bin_dir:\$PATH\" # Assinafy CLI"
187
+ ;;
188
+ bash)
189
+ append_once "$HOME/.bashrc" "export PATH=\"$bin_dir:\$PATH\" # Assinafy CLI"
190
+ ;;
191
+ *)
192
+ warn "Add $bin_dir to PATH to run assinafy from any directory."
193
+ ;;
194
+ esac
195
+ }
196
+
197
+ main "$@"
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@assinafy/cli",
3
+ "version": "1.0.0",
4
+ "description": "The official command-line interface for the Assinafy digital-signature API",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=18"
9
+ },
10
+ "bin": {
11
+ "assinafy": "./dist/cli.cjs"
12
+ },
13
+ "files": ["dist/cli.cjs", "docs/", "install.sh", "install.ps1", "README.md", "LICENSE"],
14
+ "keywords": [
15
+ "assinafy",
16
+ "cli",
17
+ "digital-signature",
18
+ "electronic-signature",
19
+ "assinatura-eletronica",
20
+ "pdf",
21
+ "api-client",
22
+ "brazil"
23
+ ],
24
+ "author": "Assinafy API Team",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/assinafy/assinafy-cli.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/assinafy/assinafy-cli/issues"
31
+ },
32
+ "homepage": "https://github.com/assinafy/assinafy-cli#readme",
33
+ "scripts": {
34
+ "dev": "tsx src/cli.ts",
35
+ "dev:watch": "tsx --watch src/cli.ts",
36
+ "build": "tsup",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "biome check .",
39
+ "lint:fix": "biome check --write .",
40
+ "test": "vitest run",
41
+ "test:watch": "vitest",
42
+ "docs": "npm run build && node scripts/gen-docs.mjs",
43
+ "verify:bundle": "node scripts/verify-bundle.mjs",
44
+ "pack:release": "npm run build && node scripts/package-release.mjs",
45
+ "prepack": "npm run build && npm run verify:bundle",
46
+ "prepublishOnly": "npm run typecheck && npm run lint && npm run test && npm run build && npm run verify:bundle"
47
+ },
48
+ "dependencies": {
49
+ "@clack/prompts": "^0.11.0",
50
+ "@commander-js/extra-typings": "^14.0.0",
51
+ "axios": "^1.7.9",
52
+ "commander": "^14.0.0",
53
+ "picocolors": "^1.1.1"
54
+ },
55
+ "devDependencies": {
56
+ "@biomejs/biome": "^1.9.4",
57
+ "@types/node": "^22.10.0",
58
+ "tsup": "^8.3.5",
59
+ "tsx": "^4.19.2",
60
+ "typescript": "^5.7.2",
61
+ "vitest": "^2.1.8"
62
+ }
63
+ }