@remixhq/core 0.1.2
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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/api.d.ts +494 -0
- package/dist/api.js +7 -0
- package/dist/auth.d.ts +27 -0
- package/dist/auth.js +15 -0
- package/dist/binding.d.ts +16 -0
- package/dist/binding.js +11 -0
- package/dist/chunk-2WGZS7CD.js +0 -0
- package/dist/chunk-34WDQCPF.js +242 -0
- package/dist/chunk-4OCNZHHR.js +0 -0
- package/dist/chunk-54CBEP2W.js +570 -0
- package/dist/chunk-55K5GHAZ.js +252 -0
- package/dist/chunk-5H5CZKGN.js +691 -0
- package/dist/chunk-5NTOJXEZ.js +223 -0
- package/dist/chunk-7WUKH3ZD.js +221 -0
- package/dist/chunk-AE2HPMUZ.js +80 -0
- package/dist/chunk-AEAOYVIL.js +200 -0
- package/dist/chunk-BJFCN2C3.js +46 -0
- package/dist/chunk-DCU3646I.js +12 -0
- package/dist/chunk-DEWAIK5X.js +11 -0
- package/dist/chunk-DRD6EVTT.js +447 -0
- package/dist/chunk-E4KAGBU7.js +134 -0
- package/dist/chunk-EF3677RE.js +93 -0
- package/dist/chunk-EVWDYCBL.js +223 -0
- package/dist/chunk-FAZUMWBS.js +93 -0
- package/dist/chunk-GC2MOT3U.js +12 -0
- package/dist/chunk-GFOBGYW4.js +252 -0
- package/dist/chunk-INDDXWAH.js +92 -0
- package/dist/chunk-K57ZFDGC.js +15 -0
- package/dist/chunk-NDA7EJJA.js +286 -0
- package/dist/chunk-NK2DA4X6.js +357 -0
- package/dist/chunk-OJMTW22J.js +286 -0
- package/dist/chunk-OMUDRPUI.js +195 -0
- package/dist/chunk-ONKKRS2C.js +239 -0
- package/dist/chunk-OWFBBWU7.js +196 -0
- package/dist/chunk-P7EM3N73.js +46 -0
- package/dist/chunk-PR5QKMHM.js +46 -0
- package/dist/chunk-RIP2MIZL.js +710 -0
- package/dist/chunk-TQHLFQY4.js +448 -0
- package/dist/chunk-TY3SSQQK.js +688 -0
- package/dist/chunk-UGKPOCN5.js +710 -0
- package/dist/chunk-VM3CGCNX.js +46 -0
- package/dist/chunk-XOQIADCH.js +223 -0
- package/dist/chunk-YZ34ICNN.js +17 -0
- package/dist/chunk-ZBMOGUSJ.js +17 -0
- package/dist/collab.d.ts +680 -0
- package/dist/collab.js +1917 -0
- package/dist/config.d.ts +22 -0
- package/dist/config.js +9 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +12 -0
- package/dist/index.cjs +1269 -0
- package/dist/index.d.cts +482 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +34 -0
- package/dist/repo.d.ts +66 -0
- package/dist/repo.js +62 -0
- package/dist/tokenProvider-BWTusyj4.d.ts +63 -0
- package/package.json +72 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComergeError
|
|
3
|
+
} from "./chunk-K57ZFDGC.js";
|
|
4
|
+
|
|
5
|
+
// src/api/client.ts
|
|
6
|
+
async function readJsonSafe(res) {
|
|
7
|
+
const ct = res.headers.get("content-type") ?? "";
|
|
8
|
+
if (!ct.toLowerCase().includes("application/json")) return null;
|
|
9
|
+
try {
|
|
10
|
+
return await res.json();
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function createApiClient(config, opts) {
|
|
16
|
+
const apiKey = (opts?.apiKey ?? "").trim();
|
|
17
|
+
const tokenProvider = opts?.tokenProvider;
|
|
18
|
+
const CLIENT_KEY_HEADER = "x-comerge-api-key";
|
|
19
|
+
async function request(path, init) {
|
|
20
|
+
if (!tokenProvider) {
|
|
21
|
+
throw new ComergeError("API client is missing a token provider.", {
|
|
22
|
+
exitCode: 1,
|
|
23
|
+
hint: "Configure auth before creating the Comerge API client."
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const auth = await tokenProvider();
|
|
27
|
+
const url = new URL(path, config.apiUrl).toString();
|
|
28
|
+
const doFetch = async (bearer) => fetch(url, {
|
|
29
|
+
...init,
|
|
30
|
+
headers: {
|
|
31
|
+
Accept: "application/json",
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
...init?.headers ?? {},
|
|
34
|
+
Authorization: `Bearer ${bearer}`,
|
|
35
|
+
...apiKey ? { [CLIENT_KEY_HEADER]: apiKey } : {}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
let res = await doFetch(auth.token);
|
|
39
|
+
if (res.status === 401 && !auth.fromEnv && auth.session?.refresh_token) {
|
|
40
|
+
const refreshed = await tokenProvider({ forceRefresh: true });
|
|
41
|
+
res = await doFetch(refreshed.token);
|
|
42
|
+
}
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
const body = await readJsonSafe(res);
|
|
45
|
+
const msg = (body && typeof body === "object" && body && "message" in body && typeof body.message === "string" ? body.message : null) ?? `Request failed (status ${res.status})`;
|
|
46
|
+
throw new ComergeError(msg, { exitCode: 1, hint: body ? JSON.stringify(body, null, 2) : null });
|
|
47
|
+
}
|
|
48
|
+
const json = await readJsonSafe(res);
|
|
49
|
+
return json ?? null;
|
|
50
|
+
}
|
|
51
|
+
async function requestBinary(path, init) {
|
|
52
|
+
if (!tokenProvider) {
|
|
53
|
+
throw new ComergeError("API client is missing a token provider.", {
|
|
54
|
+
exitCode: 1,
|
|
55
|
+
hint: "Configure auth before creating the Comerge API client."
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const auth = await tokenProvider();
|
|
59
|
+
const url = new URL(path, config.apiUrl).toString();
|
|
60
|
+
const doFetch = async (bearer) => fetch(url, {
|
|
61
|
+
...init,
|
|
62
|
+
headers: {
|
|
63
|
+
Accept: "*/*",
|
|
64
|
+
...init?.headers ?? {},
|
|
65
|
+
Authorization: `Bearer ${bearer}`,
|
|
66
|
+
...apiKey ? { [CLIENT_KEY_HEADER]: apiKey } : {}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
let res = await doFetch(auth.token);
|
|
70
|
+
if (res.status === 401 && !auth.fromEnv && auth.session?.refresh_token) {
|
|
71
|
+
const refreshed = await tokenProvider({ forceRefresh: true });
|
|
72
|
+
res = await doFetch(refreshed.token);
|
|
73
|
+
}
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const body = await readJsonSafe(res);
|
|
76
|
+
const msg = (body && typeof body === "object" && body && "message" in body && typeof body.message === "string" ? body.message : null) ?? `Request failed (status ${res.status})`;
|
|
77
|
+
throw new ComergeError(msg, { exitCode: 1, hint: body ? JSON.stringify(body, null, 2) : null });
|
|
78
|
+
}
|
|
79
|
+
const contentDisposition = res.headers.get("content-disposition") ?? "";
|
|
80
|
+
const fileNameMatch = contentDisposition.match(/filename=\"([^\"]+)\"/i);
|
|
81
|
+
return {
|
|
82
|
+
data: Buffer.from(await res.arrayBuffer()),
|
|
83
|
+
fileName: fileNameMatch?.[1] ?? null,
|
|
84
|
+
contentType: res.headers.get("content-type")
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
getMe: () => request("/v1/me", { method: "GET" }),
|
|
89
|
+
listOrganizations: () => request("/v1/organizations", { method: "GET" }),
|
|
90
|
+
listProjects: (params) => {
|
|
91
|
+
const qs = new URLSearchParams();
|
|
92
|
+
if (params?.organizationId) qs.set("organizationId", params.organizationId);
|
|
93
|
+
if (params?.clientAppId) qs.set("clientAppId", params.clientAppId);
|
|
94
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
95
|
+
return request(`/v1/projects${suffix}`, { method: "GET" });
|
|
96
|
+
},
|
|
97
|
+
resolveProjectBinding: (params) => {
|
|
98
|
+
const qs = new URLSearchParams();
|
|
99
|
+
if (params.repoFingerprint) qs.set("repoFingerprint", params.repoFingerprint);
|
|
100
|
+
if (params.remoteUrl) qs.set("remoteUrl", params.remoteUrl);
|
|
101
|
+
return request(`/v1/projects/bindings/resolve?${qs.toString()}`, { method: "GET" });
|
|
102
|
+
},
|
|
103
|
+
autoEnableDeveloper: () => request("/v1/developer/auto-enable", { method: "POST" }),
|
|
104
|
+
listClientApps: (params) => {
|
|
105
|
+
const qs = params?.orgId ? `?orgId=${encodeURIComponent(params.orgId)}` : "";
|
|
106
|
+
return request(`/v1/developer/client-apps${qs}`, { method: "GET" });
|
|
107
|
+
},
|
|
108
|
+
createClientApp: (payload) => request("/v1/developer/client-apps", { method: "POST", body: JSON.stringify(payload) }),
|
|
109
|
+
createClientAppKey: (clientAppId, payload) => request(`/v1/developer/client-apps/${encodeURIComponent(clientAppId)}/keys`, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
body: JSON.stringify(payload ?? {})
|
|
112
|
+
}),
|
|
113
|
+
listApps: (params) => {
|
|
114
|
+
const qs = new URLSearchParams();
|
|
115
|
+
if (params?.projectId) qs.set("projectId", params.projectId);
|
|
116
|
+
if (params?.organizationId) qs.set("organizationId", params.organizationId);
|
|
117
|
+
if (params?.forked) qs.set("forked", params.forked);
|
|
118
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
119
|
+
return request(`/v1/apps${suffix}`, { method: "GET" });
|
|
120
|
+
},
|
|
121
|
+
getApp: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}`, { method: "GET" }),
|
|
122
|
+
getMergeRequest: (mrId) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}`, { method: "GET" }),
|
|
123
|
+
presignImportUpload: (payload) => request("/v1/apps/import/upload/presign", { method: "POST", body: JSON.stringify(payload) }),
|
|
124
|
+
importFromUpload: (payload) => request("/v1/apps/import/upload", { method: "POST", body: JSON.stringify(payload) }),
|
|
125
|
+
presignImportUploadFirstParty: (payload) => request("/v1/apps/import/upload/presign/first-party", { method: "POST", body: JSON.stringify(payload) }),
|
|
126
|
+
importFromUploadFirstParty: (payload) => request("/v1/apps/import/upload/first-party", { method: "POST", body: JSON.stringify(payload) }),
|
|
127
|
+
importFromGithubFirstParty: (payload) => request("/v1/apps/import/github/first-party", { method: "POST", body: JSON.stringify(payload) }),
|
|
128
|
+
forkApp: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/fork`, { method: "POST", body: JSON.stringify(payload ?? {}) }),
|
|
129
|
+
downloadAppBundle: (appId) => requestBinary(`/v1/apps/${encodeURIComponent(appId)}/download.bundle`, { method: "GET" }),
|
|
130
|
+
createChangeStep: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps`, {
|
|
131
|
+
method: "POST",
|
|
132
|
+
body: JSON.stringify(payload)
|
|
133
|
+
}),
|
|
134
|
+
createCollabTurn: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/collab-turns`, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
body: JSON.stringify(payload)
|
|
137
|
+
}),
|
|
138
|
+
getChangeStep: (appId, changeStepId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/${encodeURIComponent(changeStepId)}`, { method: "GET" }),
|
|
139
|
+
listMergeRequests: (params) => {
|
|
140
|
+
const qs = new URLSearchParams();
|
|
141
|
+
if (params?.sourceAppId) qs.set("sourceAppId", params.sourceAppId);
|
|
142
|
+
if (params?.targetAppId) qs.set("targetAppId", params.targetAppId);
|
|
143
|
+
if (Array.isArray(params?.status)) {
|
|
144
|
+
for (const status of params.status) qs.append("status", status);
|
|
145
|
+
} else if (typeof params?.status === "string") {
|
|
146
|
+
qs.set("status", params.status);
|
|
147
|
+
}
|
|
148
|
+
if (params?.kind) qs.set("kind", params.kind);
|
|
149
|
+
const suffix = qs.toString() ? `?${qs.toString()}` : "";
|
|
150
|
+
return request(`/v1/merge-requests${suffix}`, { method: "GET" });
|
|
151
|
+
},
|
|
152
|
+
openMergeRequest: (sourceAppId) => request("/v1/merge-requests", { method: "POST", body: JSON.stringify({ sourceAppId }) }),
|
|
153
|
+
getMergeRequestReview: (mrId) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}/review`, { method: "GET" }),
|
|
154
|
+
updateMergeRequest: (mrId, payload) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}`, { method: "PATCH", body: JSON.stringify(payload) }),
|
|
155
|
+
createProjectInvite: (projectId, payload) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations`, {
|
|
156
|
+
method: "POST",
|
|
157
|
+
body: JSON.stringify(payload)
|
|
158
|
+
}),
|
|
159
|
+
syncUpstreamApp: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/sync-upstream`, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
body: JSON.stringify({})
|
|
162
|
+
}),
|
|
163
|
+
preflightAppReconcile: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/preflight`, {
|
|
164
|
+
method: "POST",
|
|
165
|
+
body: JSON.stringify(payload)
|
|
166
|
+
}),
|
|
167
|
+
startAppReconcile: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/start`, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
body: JSON.stringify(payload)
|
|
170
|
+
}),
|
|
171
|
+
getAppReconcile: (appId, reconcileId) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/${encodeURIComponent(reconcileId)}`, { method: "GET" }),
|
|
172
|
+
downloadAppReconcileBundle: (appId, reconcileId) => requestBinary(`/v1/apps/${encodeURIComponent(appId)}/reconcile/${encodeURIComponent(reconcileId)}/download.bundle`, {
|
|
173
|
+
method: "GET"
|
|
174
|
+
}),
|
|
175
|
+
syncLocalApp: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/sync-local`, {
|
|
176
|
+
method: "POST",
|
|
177
|
+
body: JSON.stringify(payload)
|
|
178
|
+
}),
|
|
179
|
+
initiateBundle: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/bundles`, { method: "POST", body: JSON.stringify(payload) }),
|
|
180
|
+
getBundle: (appId, bundleId) => request(`/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}`, { method: "GET" }),
|
|
181
|
+
getBundleDownloadUrl: (appId, bundleId, options) => request(
|
|
182
|
+
`/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}/download?redirect=${options?.redirect ?? false}`,
|
|
183
|
+
{ method: "GET" }
|
|
184
|
+
),
|
|
185
|
+
getBundleAssetsDownloadUrl: (appId, bundleId, options) => {
|
|
186
|
+
const qs = new URLSearchParams({
|
|
187
|
+
redirect: String(options?.redirect ?? false),
|
|
188
|
+
kind: options?.kind ?? "metro-assets"
|
|
189
|
+
});
|
|
190
|
+
return request(
|
|
191
|
+
`/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}/assets/download?${qs.toString()}`,
|
|
192
|
+
{ method: "GET" }
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export {
|
|
199
|
+
createApiClient
|
|
200
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComergeError
|
|
3
|
+
} from "./chunk-ZBMOGUSJ.js";
|
|
4
|
+
|
|
5
|
+
// src/config/model.ts
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
var DEFAULT_API_URL = "https://api.remix.one";
|
|
8
|
+
var DEFAULT_SUPABASE_URL = "https://xtfxwbckjpfmqubnsusu.supabase.co";
|
|
9
|
+
var DEFAULT_SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh0Znh3YmNranBmbXF1Ym5zdXN1Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjA2MDEyMzAsImV4cCI6MjA3NjE3NzIzMH0.dzWGAWrK4CvrmHVHzf8w7JlUZohdap0ZPnLZnABMV8s";
|
|
10
|
+
function isValidUrl(value) {
|
|
11
|
+
try {
|
|
12
|
+
new URL(value);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var urlSchema = z.string().min(1).transform((s) => s.trim()).refine((s) => isValidUrl(s), "Invalid URL.").transform((s) => s.replace(/\/+$/, ""));
|
|
19
|
+
var configSchema = z.object({
|
|
20
|
+
apiUrl: urlSchema,
|
|
21
|
+
supabaseUrl: urlSchema,
|
|
22
|
+
supabaseAnonKey: z.string().min(1)
|
|
23
|
+
});
|
|
24
|
+
var cachedConfig = null;
|
|
25
|
+
async function resolveConfig(_opts) {
|
|
26
|
+
if (cachedConfig) return cachedConfig;
|
|
27
|
+
const cfgRaw = {
|
|
28
|
+
apiUrl: DEFAULT_API_URL,
|
|
29
|
+
supabaseUrl: DEFAULT_SUPABASE_URL,
|
|
30
|
+
supabaseAnonKey: DEFAULT_SUPABASE_ANON_KEY
|
|
31
|
+
};
|
|
32
|
+
const parsedCfg = configSchema.safeParse(cfgRaw);
|
|
33
|
+
if (!parsedCfg.success) {
|
|
34
|
+
throw new ComergeError("Invalid core configuration.", {
|
|
35
|
+
exitCode: 1,
|
|
36
|
+
hint: parsedCfg.error.issues.map((i) => `${i.path.join(".") || "config"}: ${i.message}`).join("; ")
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
cachedConfig = parsedCfg.data;
|
|
40
|
+
return parsedCfg.data;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
configSchema,
|
|
45
|
+
resolveConfig
|
|
46
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/errors/errorCodes.ts
|
|
2
|
+
var COMERGE_ERROR_CODES = {
|
|
3
|
+
REPO_LOCK_HELD: "REPO_LOCK_HELD",
|
|
4
|
+
REPO_LOCK_TIMEOUT: "REPO_LOCK_TIMEOUT",
|
|
5
|
+
REPO_LOCK_STALE_RECOVERED: "REPO_LOCK_STALE_RECOVERED",
|
|
6
|
+
REPO_STATE_CHANGED_DURING_OPERATION: "REPO_STATE_CHANGED_DURING_OPERATION",
|
|
7
|
+
PREFERRED_BRANCH_MISMATCH: "PREFERRED_BRANCH_MISMATCH"
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
COMERGE_ERROR_CODES
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/errors/errorCodes.ts
|
|
2
|
+
var COMERGE_ERROR_CODES = {
|
|
3
|
+
REPO_LOCK_HELD: "REPO_LOCK_HELD",
|
|
4
|
+
REPO_LOCK_TIMEOUT: "REPO_LOCK_TIMEOUT",
|
|
5
|
+
REPO_LOCK_STALE_RECOVERED: "REPO_LOCK_STALE_RECOVERED",
|
|
6
|
+
REPO_STATE_CHANGED_DURING_OPERATION: "REPO_STATE_CHANGED_DURING_OPERATION"
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
COMERGE_ERROR_CODES
|
|
11
|
+
};
|