@memberjunction/installer 0.0.1 → 5.6.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.
Files changed (90) hide show
  1. package/dist/InstallerEngine.d.ts +182 -0
  2. package/dist/InstallerEngine.d.ts.map +1 -0
  3. package/dist/InstallerEngine.js +571 -0
  4. package/dist/InstallerEngine.js.map +1 -0
  5. package/dist/adapters/FileSystemAdapter.d.ts +197 -0
  6. package/dist/adapters/FileSystemAdapter.d.ts.map +1 -0
  7. package/dist/adapters/FileSystemAdapter.js +355 -0
  8. package/dist/adapters/FileSystemAdapter.js.map +1 -0
  9. package/dist/adapters/GitHubReleaseProvider.d.ts +197 -0
  10. package/dist/adapters/GitHubReleaseProvider.d.ts.map +1 -0
  11. package/dist/adapters/GitHubReleaseProvider.js +348 -0
  12. package/dist/adapters/GitHubReleaseProvider.js.map +1 -0
  13. package/dist/adapters/ProcessRunner.d.ts +174 -0
  14. package/dist/adapters/ProcessRunner.d.ts.map +1 -0
  15. package/dist/adapters/ProcessRunner.js +264 -0
  16. package/dist/adapters/ProcessRunner.js.map +1 -0
  17. package/dist/adapters/SqlServerAdapter.d.ts +78 -0
  18. package/dist/adapters/SqlServerAdapter.d.ts.map +1 -0
  19. package/dist/adapters/SqlServerAdapter.js +120 -0
  20. package/dist/adapters/SqlServerAdapter.js.map +1 -0
  21. package/dist/errors/InstallerError.d.ts +92 -0
  22. package/dist/errors/InstallerError.d.ts.map +1 -0
  23. package/dist/errors/InstallerError.js +66 -0
  24. package/dist/errors/InstallerError.js.map +1 -0
  25. package/dist/events/InstallerEvents.d.ts +255 -0
  26. package/dist/events/InstallerEvents.d.ts.map +1 -0
  27. package/dist/events/InstallerEvents.js +96 -0
  28. package/dist/events/InstallerEvents.js.map +1 -0
  29. package/dist/index.d.ts +59 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +63 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/models/Diagnostics.d.ts +121 -0
  34. package/dist/models/Diagnostics.d.ts.map +1 -0
  35. package/dist/models/Diagnostics.js +75 -0
  36. package/dist/models/Diagnostics.js.map +1 -0
  37. package/dist/models/InstallConfig.d.ts +139 -0
  38. package/dist/models/InstallConfig.d.ts.map +1 -0
  39. package/dist/models/InstallConfig.js +207 -0
  40. package/dist/models/InstallConfig.js.map +1 -0
  41. package/dist/models/InstallPlan.d.ts +189 -0
  42. package/dist/models/InstallPlan.d.ts.map +1 -0
  43. package/dist/models/InstallPlan.js +117 -0
  44. package/dist/models/InstallPlan.js.map +1 -0
  45. package/dist/models/InstallState.d.ts +173 -0
  46. package/dist/models/InstallState.d.ts.map +1 -0
  47. package/dist/models/InstallState.js +203 -0
  48. package/dist/models/InstallState.js.map +1 -0
  49. package/dist/models/VersionInfo.d.ts +53 -0
  50. package/dist/models/VersionInfo.d.ts.map +1 -0
  51. package/dist/models/VersionInfo.js +2 -0
  52. package/dist/models/VersionInfo.js.map +1 -0
  53. package/dist/phases/CodeGenPhase.d.ts +364 -0
  54. package/dist/phases/CodeGenPhase.d.ts.map +1 -0
  55. package/dist/phases/CodeGenPhase.js +1086 -0
  56. package/dist/phases/CodeGenPhase.js.map +1 -0
  57. package/dist/phases/ConfigurePhase.d.ts +86 -0
  58. package/dist/phases/ConfigurePhase.d.ts.map +1 -0
  59. package/dist/phases/ConfigurePhase.js +439 -0
  60. package/dist/phases/ConfigurePhase.js.map +1 -0
  61. package/dist/phases/DatabaseProvisionPhase.d.ts +82 -0
  62. package/dist/phases/DatabaseProvisionPhase.d.ts.map +1 -0
  63. package/dist/phases/DatabaseProvisionPhase.js +284 -0
  64. package/dist/phases/DatabaseProvisionPhase.js.map +1 -0
  65. package/dist/phases/DependencyPhase.d.ts +88 -0
  66. package/dist/phases/DependencyPhase.d.ts.map +1 -0
  67. package/dist/phases/DependencyPhase.js +237 -0
  68. package/dist/phases/DependencyPhase.js.map +1 -0
  69. package/dist/phases/MigratePhase.d.ts +70 -0
  70. package/dist/phases/MigratePhase.d.ts.map +1 -0
  71. package/dist/phases/MigratePhase.js +96 -0
  72. package/dist/phases/MigratePhase.js.map +1 -0
  73. package/dist/phases/PlatformCompatPhase.d.ts +193 -0
  74. package/dist/phases/PlatformCompatPhase.d.ts.map +1 -0
  75. package/dist/phases/PlatformCompatPhase.js +587 -0
  76. package/dist/phases/PlatformCompatPhase.js.map +1 -0
  77. package/dist/phases/PreflightPhase.d.ts +119 -0
  78. package/dist/phases/PreflightPhase.d.ts.map +1 -0
  79. package/dist/phases/PreflightPhase.js +394 -0
  80. package/dist/phases/PreflightPhase.js.map +1 -0
  81. package/dist/phases/ScaffoldPhase.d.ts +99 -0
  82. package/dist/phases/ScaffoldPhase.d.ts.map +1 -0
  83. package/dist/phases/ScaffoldPhase.js +235 -0
  84. package/dist/phases/ScaffoldPhase.js.map +1 -0
  85. package/dist/phases/SmokeTestPhase.d.ts +111 -0
  86. package/dist/phases/SmokeTestPhase.d.ts.map +1 -0
  87. package/dist/phases/SmokeTestPhase.js +426 -0
  88. package/dist/phases/SmokeTestPhase.js.map +1 -0
  89. package/package.json +26 -7
  90. package/README.md +0 -45
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Adapter for listing and downloading MemberJunction releases from GitHub.
3
+ *
4
+ * Uses the unauthenticated GitHub REST API (60 requests/hour rate limit,
5
+ * which is plenty for installer use).
6
+ *
7
+ * Supports two release strategies:
8
+ * 1. **Formal GitHub Releases** (preferred) — includes release notes, pre-built
9
+ * ZIP assets, and prerelease flags.
10
+ * 2. **Git tags fallback** — for repos that only publish version tags without
11
+ * formal Release objects. Uses zipball URLs and fetches commit dates for
12
+ * display in the version picker.
13
+ *
14
+ * The provider is used by {@link ScaffoldPhase} to resolve versions and download
15
+ * release archives, and by {@link InstallerEngine.ListVersions} to populate
16
+ * the interactive version picker.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const github = new GitHubReleaseProvider();
21
+ * const versions = await github.ListReleases();
22
+ * const specific = await github.GetReleaseByTag('v5.1.0');
23
+ * await github.DownloadRelease(specific.DownloadUrl, '/tmp/release.zip', (pct) => {
24
+ * console.log(`${pct}% downloaded`);
25
+ * });
26
+ * ```
27
+ */
28
+ import type { VersionInfo } from '../models/VersionInfo.js';
29
+ /**
30
+ * Adapter that lists and downloads MemberJunction releases from GitHub.
31
+ *
32
+ * All network calls use the unauthenticated GitHub REST API with a
33
+ * `User-Agent: MJ-Installer` header. The unauthenticated rate limit is
34
+ * 60 requests per hour per IP, which is sufficient for installer workflows.
35
+ *
36
+ * The provider first attempts to use formal GitHub Releases (which include
37
+ * uploaded ZIP assets and release notes). If no releases are found, it falls
38
+ * back to listing git tags and constructing zipball download URLs.
39
+ */
40
+ export declare class GitHubReleaseProvider {
41
+ /** GitHub organization or user that owns the repository. */
42
+ private owner;
43
+ /** GitHub repository name. */
44
+ private repo;
45
+ /**
46
+ * Create a new GitHubReleaseProvider.
47
+ *
48
+ * @param owner - GitHub organization or user (default: `"MemberJunction"`)
49
+ * @param repo - Repository name (default: `"MJ"`)
50
+ */
51
+ constructor(owner?: string, repo?: string);
52
+ /**
53
+ * List available MemberJunction versions, sorted most recent first.
54
+ *
55
+ * Tries formal GitHub Releases first (up to 50). If no releases are found,
56
+ * falls back to listing git tags (up to 30) and fetching commit dates for
57
+ * the most recent {@link MAX_TAG_DATE_LOOKUPS} tags.
58
+ *
59
+ * @param includePrerelease - If `true`, includes releases marked as prerelease
60
+ * on GitHub. Defaults to `false`.
61
+ * @returns Array of {@link VersionInfo} objects sorted by release date descending.
62
+ * @throws Error if the GitHub API request fails.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const provider = new GitHubReleaseProvider();
67
+ * const stable = await provider.ListReleases();
68
+ * const all = await provider.ListReleases(true); // includes prereleases
69
+ * ```
70
+ */
71
+ ListReleases(includePrerelease?: boolean): Promise<VersionInfo[]>;
72
+ /**
73
+ * Get a specific version by its git tag name.
74
+ *
75
+ * Tries to resolve as a formal GitHub Release first. If the release is not
76
+ * found (404), falls back to looking up the tag via the Commits API to get
77
+ * the commit date and constructs a zipball download URL.
78
+ *
79
+ * @param tag - The git tag to look up (e.g., `"v5.1.0"`).
80
+ * @returns A {@link VersionInfo} for the requested tag.
81
+ * @throws Error if the tag does not exist in the repository.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const provider = new GitHubReleaseProvider();
86
+ * const version = await provider.GetReleaseByTag('v5.1.0');
87
+ * console.log(version.DownloadUrl);
88
+ * ```
89
+ */
90
+ GetReleaseByTag(tag: string): Promise<VersionInfo>;
91
+ /**
92
+ * Download a release ZIP archive to a local file path.
93
+ *
94
+ * Streams the download to disk to avoid holding the entire archive in memory.
95
+ * Follows HTTP redirects automatically (GitHub often 302-redirects to a CDN).
96
+ *
97
+ * @param downloadUrl - URL to download from (either an asset URL or a zipball URL).
98
+ * @param destPath - Absolute path where the ZIP file will be written.
99
+ * @param onProgress - Optional callback invoked with download percentage (0–100)
100
+ * as data arrives. Only called if the server provides a `Content-Length` header.
101
+ * @throws Error if the HTTP request fails or the response has no body.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const provider = new GitHubReleaseProvider();
106
+ * const version = await provider.GetReleaseByTag('v5.1.0');
107
+ * await provider.DownloadRelease(version.DownloadUrl, '/tmp/mj.zip', (pct) => {
108
+ * process.stdout.write(`\rDownloading... ${pct}%`);
109
+ * });
110
+ * ```
111
+ */
112
+ DownloadRelease(downloadUrl: string, destPath: string, onProgress?: (percent: number) => void): Promise<void>;
113
+ /**
114
+ * Fetch formal GitHub Releases and map them to {@link VersionInfo} objects.
115
+ *
116
+ * @param includePrerelease - Whether to include prerelease versions.
117
+ * @returns Array of versions, or empty array if no releases exist.
118
+ * @throws Error on API failure.
119
+ */
120
+ private fetchFormalReleases;
121
+ /**
122
+ * Convert a GitHub Release API response into a {@link VersionInfo}.
123
+ *
124
+ * Prefers an uploaded `.zip` asset if one exists; otherwise falls back to
125
+ * the GitHub-generated `zipball_url` (source code archive).
126
+ *
127
+ * @param release - Raw GitHub Release response.
128
+ * @returns Mapped {@link VersionInfo}.
129
+ */
130
+ private mapRelease;
131
+ /**
132
+ * Find the best ZIP download URL for a release.
133
+ *
134
+ * Looks for an uploaded asset with a `.zip` extension and `zip` content type.
135
+ * If none is found, returns the GitHub-generated `zipball_url`.
136
+ *
137
+ * @param release - Raw GitHub Release response.
138
+ * @returns Download URL for the release archive.
139
+ */
140
+ private findZipAsset;
141
+ /**
142
+ * Fetch git tags and map them to {@link VersionInfo} objects.
143
+ *
144
+ * Used as a fallback when the repository has no formal GitHub Releases.
145
+ * Fetches up to 30 tags and looks up commit dates for the most recent
146
+ * {@link MAX_TAG_DATE_LOOKUPS} to minimize API usage.
147
+ *
148
+ * @returns Array of versions derived from git tags.
149
+ * @throws Error on API failure.
150
+ */
151
+ private fetchTagVersions;
152
+ /**
153
+ * Look up a single tag by name and return its {@link VersionInfo}.
154
+ *
155
+ * Uses the Commits API (which accepts tag names as a ref) to get the
156
+ * commit date, then constructs a zipball download URL.
157
+ *
158
+ * @param tagName - The git tag to look up (e.g., `"v5.1.0"`).
159
+ * @returns Version info for the tag.
160
+ * @throws Error if the tag does not exist.
161
+ */
162
+ private fetchSingleTagVersion;
163
+ /**
164
+ * Convert a GitHub Tag API response into a {@link VersionInfo}.
165
+ *
166
+ * Fetches the commit date from the tag's commit URL to populate
167
+ * the {@link VersionInfo.ReleaseDate} field.
168
+ *
169
+ * @param tag - Raw GitHub Tag response.
170
+ * @returns Mapped {@link VersionInfo}.
171
+ */
172
+ private mapTag;
173
+ /**
174
+ * Fetch the committer date for a commit via the GitHub Commits API.
175
+ *
176
+ * Returns the current date as a fallback if the API call fails, to avoid
177
+ * blocking the version listing over a single failed date lookup.
178
+ *
179
+ * @param commitUrl - Full API URL for the commit (provided by the Tags API).
180
+ * @returns The commit date, or `new Date()` on failure.
181
+ */
182
+ private fetchCommitDate;
183
+ /**
184
+ * Make an authenticated-style GET request to the GitHub REST API.
185
+ *
186
+ * Sets the `Accept: application/vnd.github+json` header (recommended by GitHub)
187
+ * and a `User-Agent` header (required by GitHub — requests without one are rejected).
188
+ *
189
+ * This uses the unauthenticated API, so the rate limit is 60 requests/hour/IP.
190
+ * For installer use cases (a handful of calls per install), this is sufficient.
191
+ *
192
+ * @param url - Full GitHub API URL to fetch.
193
+ * @returns The raw `Response` object (caller is responsible for checking `.ok`).
194
+ */
195
+ private githubFetch;
196
+ }
197
+ //# sourceMappingURL=GitHubReleaseProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitHubReleaseProvider.d.ts","sourceRoot":"","sources":["../../src/adapters/GitHubReleaseProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAyF5D;;;;;;;;;;GAUG;AACH,qBAAa,qBAAqB;IAChC,4DAA4D;IAC5D,OAAO,CAAC,KAAK,CAAS;IAEtB,8BAA8B;IAC9B,OAAO,CAAC,IAAI,CAAS;IAErB;;;;;OAKG;gBACS,KAAK,GAAE,MAAmB,EAAE,IAAI,GAAE,MAAkB;IAShE;;;;;;;;;;;;;;;;;;OAkBG;IACG,YAAY,CAAC,iBAAiB,GAAE,OAAe,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAS9E;;;;;;;;;;;;;;;;;OAiBG;IACG,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAaxD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACrC,OAAO,CAAC,IAAI,CAAC;IAyChB;;;;;;OAMG;YACW,mBAAmB;IAejC;;;;;;;;OAQG;IACH,OAAO,CAAC,UAAU;IAgBlB;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;IAcpB;;;;;;;;;OASG;YACW,gBAAgB;IAmB9B;;;;;;;;;OASG;YACW,qBAAqB;IAoBnC;;;;;;;;OAQG;YACW,MAAM;IAYpB;;;;;;;;OAQG;YACW,eAAe;IAe7B;;;;;;;;;;;OAWG;YACW,WAAW;CAQ1B"}
@@ -0,0 +1,348 @@
1
+ /**
2
+ * Adapter for listing and downloading MemberJunction releases from GitHub.
3
+ *
4
+ * Uses the unauthenticated GitHub REST API (60 requests/hour rate limit,
5
+ * which is plenty for installer use).
6
+ *
7
+ * Supports two release strategies:
8
+ * 1. **Formal GitHub Releases** (preferred) — includes release notes, pre-built
9
+ * ZIP assets, and prerelease flags.
10
+ * 2. **Git tags fallback** — for repos that only publish version tags without
11
+ * formal Release objects. Uses zipball URLs and fetches commit dates for
12
+ * display in the version picker.
13
+ *
14
+ * The provider is used by {@link ScaffoldPhase} to resolve versions and download
15
+ * release archives, and by {@link InstallerEngine.ListVersions} to populate
16
+ * the interactive version picker.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const github = new GitHubReleaseProvider();
21
+ * const versions = await github.ListReleases();
22
+ * const specific = await github.GetReleaseByTag('v5.1.0');
23
+ * await github.DownloadRelease(specific.DownloadUrl, '/tmp/release.zip', (pct) => {
24
+ * console.log(`${pct}% downloaded`);
25
+ * });
26
+ * ```
27
+ */
28
+ import fs from 'node:fs';
29
+ import { pipeline } from 'node:stream/promises';
30
+ import { Readable } from 'node:stream';
31
+ /** Base URL for all GitHub REST API calls. */
32
+ const GITHUB_API_BASE = 'https://api.github.com';
33
+ /** Default GitHub organization that owns the MemberJunction repository. */
34
+ const REPO_OWNER = 'MemberJunction';
35
+ /** Default GitHub repository name. */
36
+ const REPO_NAME = 'MJ';
37
+ /** Maximum tags to fetch commit dates for (keeps API usage reasonable). */
38
+ const MAX_TAG_DATE_LOOKUPS = 20;
39
+ /**
40
+ * Adapter that lists and downloads MemberJunction releases from GitHub.
41
+ *
42
+ * All network calls use the unauthenticated GitHub REST API with a
43
+ * `User-Agent: MJ-Installer` header. The unauthenticated rate limit is
44
+ * 60 requests per hour per IP, which is sufficient for installer workflows.
45
+ *
46
+ * The provider first attempts to use formal GitHub Releases (which include
47
+ * uploaded ZIP assets and release notes). If no releases are found, it falls
48
+ * back to listing git tags and constructing zipball download URLs.
49
+ */
50
+ export class GitHubReleaseProvider {
51
+ /**
52
+ * Create a new GitHubReleaseProvider.
53
+ *
54
+ * @param owner - GitHub organization or user (default: `"MemberJunction"`)
55
+ * @param repo - Repository name (default: `"MJ"`)
56
+ */
57
+ constructor(owner = REPO_OWNER, repo = REPO_NAME) {
58
+ this.owner = owner;
59
+ this.repo = repo;
60
+ }
61
+ // ---------------------------------------------------------------------------
62
+ // Public API
63
+ // ---------------------------------------------------------------------------
64
+ /**
65
+ * List available MemberJunction versions, sorted most recent first.
66
+ *
67
+ * Tries formal GitHub Releases first (up to 50). If no releases are found,
68
+ * falls back to listing git tags (up to 30) and fetching commit dates for
69
+ * the most recent {@link MAX_TAG_DATE_LOOKUPS} tags.
70
+ *
71
+ * @param includePrerelease - If `true`, includes releases marked as prerelease
72
+ * on GitHub. Defaults to `false`.
73
+ * @returns Array of {@link VersionInfo} objects sorted by release date descending.
74
+ * @throws Error if the GitHub API request fails.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const provider = new GitHubReleaseProvider();
79
+ * const stable = await provider.ListReleases();
80
+ * const all = await provider.ListReleases(true); // includes prereleases
81
+ * ```
82
+ */
83
+ async ListReleases(includePrerelease = false) {
84
+ const releases = await this.fetchFormalReleases(includePrerelease);
85
+ if (releases.length > 0) {
86
+ return releases;
87
+ }
88
+ return this.fetchTagVersions();
89
+ }
90
+ /**
91
+ * Get a specific version by its git tag name.
92
+ *
93
+ * Tries to resolve as a formal GitHub Release first. If the release is not
94
+ * found (404), falls back to looking up the tag via the Commits API to get
95
+ * the commit date and constructs a zipball download URL.
96
+ *
97
+ * @param tag - The git tag to look up (e.g., `"v5.1.0"`).
98
+ * @returns A {@link VersionInfo} for the requested tag.
99
+ * @throws Error if the tag does not exist in the repository.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const provider = new GitHubReleaseProvider();
104
+ * const version = await provider.GetReleaseByTag('v5.1.0');
105
+ * console.log(version.DownloadUrl);
106
+ * ```
107
+ */
108
+ async GetReleaseByTag(tag) {
109
+ // Try formal release first
110
+ const releaseUrl = `${GITHUB_API_BASE}/repos/${this.owner}/${this.repo}/releases/tags/${tag}`;
111
+ const releaseResponse = await this.githubFetch(releaseUrl);
112
+ if (releaseResponse.ok) {
113
+ const release = (await releaseResponse.json());
114
+ return this.mapRelease(release);
115
+ }
116
+ // Fall back to tag lookup
117
+ return this.fetchSingleTagVersion(tag);
118
+ }
119
+ /**
120
+ * Download a release ZIP archive to a local file path.
121
+ *
122
+ * Streams the download to disk to avoid holding the entire archive in memory.
123
+ * Follows HTTP redirects automatically (GitHub often 302-redirects to a CDN).
124
+ *
125
+ * @param downloadUrl - URL to download from (either an asset URL or a zipball URL).
126
+ * @param destPath - Absolute path where the ZIP file will be written.
127
+ * @param onProgress - Optional callback invoked with download percentage (0–100)
128
+ * as data arrives. Only called if the server provides a `Content-Length` header.
129
+ * @throws Error if the HTTP request fails or the response has no body.
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * const provider = new GitHubReleaseProvider();
134
+ * const version = await provider.GetReleaseByTag('v5.1.0');
135
+ * await provider.DownloadRelease(version.DownloadUrl, '/tmp/mj.zip', (pct) => {
136
+ * process.stdout.write(`\rDownloading... ${pct}%`);
137
+ * });
138
+ * ```
139
+ */
140
+ async DownloadRelease(downloadUrl, destPath, onProgress) {
141
+ const response = await fetch(downloadUrl, {
142
+ headers: { 'User-Agent': 'MJ-Installer' },
143
+ redirect: 'follow',
144
+ });
145
+ if (!response.ok) {
146
+ throw new Error(`Download failed: ${response.status} ${response.statusText}`);
147
+ }
148
+ if (!response.body) {
149
+ throw new Error('Download response has no body');
150
+ }
151
+ const contentLength = Number(response.headers.get('content-length') ?? 0);
152
+ const fileStream = fs.createWriteStream(destPath);
153
+ const reader = response.body.getReader();
154
+ let receivedBytes = 0;
155
+ const readableStream = new Readable({
156
+ async read() {
157
+ const { done, value } = await reader.read();
158
+ if (done) {
159
+ this.push(null);
160
+ return;
161
+ }
162
+ receivedBytes += value.byteLength;
163
+ if (onProgress && contentLength > 0) {
164
+ onProgress(Math.round((receivedBytes / contentLength) * 100));
165
+ }
166
+ this.push(Buffer.from(value));
167
+ },
168
+ });
169
+ await pipeline(readableStream, fileStream);
170
+ }
171
+ // ---------------------------------------------------------------------------
172
+ // Formal releases (repos that use GitHub Releases)
173
+ // ---------------------------------------------------------------------------
174
+ /**
175
+ * Fetch formal GitHub Releases and map them to {@link VersionInfo} objects.
176
+ *
177
+ * @param includePrerelease - Whether to include prerelease versions.
178
+ * @returns Array of versions, or empty array if no releases exist.
179
+ * @throws Error on API failure.
180
+ */
181
+ async fetchFormalReleases(includePrerelease) {
182
+ const url = `${GITHUB_API_BASE}/repos/${this.owner}/${this.repo}/releases?per_page=50`;
183
+ const response = await this.githubFetch(url);
184
+ if (!response.ok) {
185
+ throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
186
+ }
187
+ const releases = (await response.json());
188
+ return releases
189
+ .filter((r) => includePrerelease || !r.prerelease)
190
+ .map((r) => this.mapRelease(r));
191
+ }
192
+ /**
193
+ * Convert a GitHub Release API response into a {@link VersionInfo}.
194
+ *
195
+ * Prefers an uploaded `.zip` asset if one exists; otherwise falls back to
196
+ * the GitHub-generated `zipball_url` (source code archive).
197
+ *
198
+ * @param release - Raw GitHub Release response.
199
+ * @returns Mapped {@link VersionInfo}.
200
+ */
201
+ mapRelease(release) {
202
+ const downloadUrl = this.findZipAsset(release);
203
+ const notesExcerpt = release.body
204
+ ? release.body.slice(0, 500) + (release.body.length > 500 ? '...' : '')
205
+ : undefined;
206
+ return {
207
+ Tag: release.tag_name,
208
+ Name: release.name || release.tag_name,
209
+ ReleaseDate: new Date(release.published_at),
210
+ Prerelease: release.prerelease,
211
+ DownloadUrl: downloadUrl,
212
+ Notes: notesExcerpt,
213
+ };
214
+ }
215
+ /**
216
+ * Find the best ZIP download URL for a release.
217
+ *
218
+ * Looks for an uploaded asset with a `.zip` extension and `zip` content type.
219
+ * If none is found, returns the GitHub-generated `zipball_url`.
220
+ *
221
+ * @param release - Raw GitHub Release response.
222
+ * @returns Download URL for the release archive.
223
+ */
224
+ findZipAsset(release) {
225
+ const zipAsset = release.assets.find((a) => a.name.endsWith('.zip') && a.content_type.includes('zip'));
226
+ if (zipAsset) {
227
+ return zipAsset.browser_download_url;
228
+ }
229
+ return release.zipball_url;
230
+ }
231
+ // ---------------------------------------------------------------------------
232
+ // Tag-based fallback (repos that only publish git tags)
233
+ // ---------------------------------------------------------------------------
234
+ /**
235
+ * Fetch git tags and map them to {@link VersionInfo} objects.
236
+ *
237
+ * Used as a fallback when the repository has no formal GitHub Releases.
238
+ * Fetches up to 30 tags and looks up commit dates for the most recent
239
+ * {@link MAX_TAG_DATE_LOOKUPS} to minimize API usage.
240
+ *
241
+ * @returns Array of versions derived from git tags.
242
+ * @throws Error on API failure.
243
+ */
244
+ async fetchTagVersions() {
245
+ const url = `${GITHUB_API_BASE}/repos/${this.owner}/${this.repo}/tags?per_page=30`;
246
+ const response = await this.githubFetch(url);
247
+ if (!response.ok) {
248
+ throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
249
+ }
250
+ const tags = (await response.json());
251
+ const tagsToProcess = tags.slice(0, MAX_TAG_DATE_LOOKUPS);
252
+ // Fetch commit dates in parallel for display in the version picker
253
+ const versions = await Promise.all(tagsToProcess.map((tag) => this.mapTag(tag)));
254
+ return versions;
255
+ }
256
+ /**
257
+ * Look up a single tag by name and return its {@link VersionInfo}.
258
+ *
259
+ * Uses the Commits API (which accepts tag names as a ref) to get the
260
+ * commit date, then constructs a zipball download URL.
261
+ *
262
+ * @param tagName - The git tag to look up (e.g., `"v5.1.0"`).
263
+ * @returns Version info for the tag.
264
+ * @throws Error if the tag does not exist.
265
+ */
266
+ async fetchSingleTagVersion(tagName) {
267
+ // Use the commits API which accepts tag names as ref
268
+ const commitUrl = `${GITHUB_API_BASE}/repos/${this.owner}/${this.repo}/commits/${tagName}`;
269
+ const response = await this.githubFetch(commitUrl);
270
+ if (!response.ok) {
271
+ throw new Error(`Tag "${tagName}" not found (HTTP ${response.status}).`);
272
+ }
273
+ const commitData = (await response.json());
274
+ return {
275
+ Tag: tagName,
276
+ Name: tagName,
277
+ ReleaseDate: new Date(commitData.commit.committer.date),
278
+ Prerelease: false,
279
+ DownloadUrl: `${GITHUB_API_BASE}/repos/${this.owner}/${this.repo}/zipball/refs/tags/${tagName}`,
280
+ Notes: undefined,
281
+ };
282
+ }
283
+ /**
284
+ * Convert a GitHub Tag API response into a {@link VersionInfo}.
285
+ *
286
+ * Fetches the commit date from the tag's commit URL to populate
287
+ * the {@link VersionInfo.ReleaseDate} field.
288
+ *
289
+ * @param tag - Raw GitHub Tag response.
290
+ * @returns Mapped {@link VersionInfo}.
291
+ */
292
+ async mapTag(tag) {
293
+ const commitDate = await this.fetchCommitDate(tag.commit.url);
294
+ return {
295
+ Tag: tag.name,
296
+ Name: tag.name,
297
+ ReleaseDate: commitDate,
298
+ Prerelease: false,
299
+ DownloadUrl: tag.zipball_url,
300
+ Notes: undefined,
301
+ };
302
+ }
303
+ /**
304
+ * Fetch the committer date for a commit via the GitHub Commits API.
305
+ *
306
+ * Returns the current date as a fallback if the API call fails, to avoid
307
+ * blocking the version listing over a single failed date lookup.
308
+ *
309
+ * @param commitUrl - Full API URL for the commit (provided by the Tags API).
310
+ * @returns The commit date, or `new Date()` on failure.
311
+ */
312
+ async fetchCommitDate(commitUrl) {
313
+ try {
314
+ const response = await this.githubFetch(commitUrl);
315
+ if (!response.ok)
316
+ return new Date();
317
+ const data = (await response.json());
318
+ return new Date(data.commit.committer.date);
319
+ }
320
+ catch {
321
+ return new Date();
322
+ }
323
+ }
324
+ // ---------------------------------------------------------------------------
325
+ // Shared HTTP helper
326
+ // ---------------------------------------------------------------------------
327
+ /**
328
+ * Make an authenticated-style GET request to the GitHub REST API.
329
+ *
330
+ * Sets the `Accept: application/vnd.github+json` header (recommended by GitHub)
331
+ * and a `User-Agent` header (required by GitHub — requests without one are rejected).
332
+ *
333
+ * This uses the unauthenticated API, so the rate limit is 60 requests/hour/IP.
334
+ * For installer use cases (a handful of calls per install), this is sufficient.
335
+ *
336
+ * @param url - Full GitHub API URL to fetch.
337
+ * @returns The raw `Response` object (caller is responsible for checking `.ok`).
338
+ */
339
+ async githubFetch(url) {
340
+ return fetch(url, {
341
+ headers: {
342
+ 'Accept': 'application/vnd.github+json',
343
+ 'User-Agent': 'MJ-Installer',
344
+ },
345
+ });
346
+ }
347
+ }
348
+ //# sourceMappingURL=GitHubReleaseProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitHubReleaseProvider.js","sourceRoot":"","sources":["../../src/adapters/GitHubReleaseProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,8CAA8C;AAC9C,MAAM,eAAe,GAAG,wBAAwB,CAAC;AAEjD,2EAA2E;AAC3E,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAEpC,sCAAsC;AACtC,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,2EAA2E;AAC3E,MAAM,oBAAoB,GAAG,EAAE,CAAC;AA6EhC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,qBAAqB;IAOhC;;;;;OAKG;IACH,YAAY,QAAgB,UAAU,EAAE,OAAe,SAAS;QAC9D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,8EAA8E;IAC9E,aAAa;IACb,8EAA8E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