@remixhq/core 0.1.6 → 0.1.8

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/dist/api.d.ts CHANGED
@@ -204,6 +204,9 @@ type ReconcilePreflightResponse = {
204
204
  targetHeadCommitHash: string;
205
205
  warnings: string[];
206
206
  };
207
+ type OrganizationMemberRole = "owner" | "admin" | "member" | "viewer";
208
+ type ProjectMemberRole = "owner" | "maintainer" | "editor" | "viewer";
209
+ type AppMemberRole = "owner" | "maintainer" | "editor" | "viewer";
207
210
  type AppReconcileResponse = {
208
211
  id: string;
209
212
  appId: string;
@@ -436,6 +439,18 @@ type ApiClient = {
436
439
  role?: string;
437
440
  ttlDays?: number;
438
441
  }): Promise<Json>;
442
+ listOrganizationMembers(orgId: string): Promise<Json>;
443
+ updateOrganizationMember(orgId: string, userId: string, payload: {
444
+ role: OrganizationMemberRole;
445
+ }): Promise<Json>;
446
+ listProjectMembers(projectId: string): Promise<Json>;
447
+ updateProjectMember(projectId: string, userId: string, payload: {
448
+ role: ProjectMemberRole;
449
+ }): Promise<Json>;
450
+ listAppMembers(appId: string): Promise<Json>;
451
+ updateAppMember(appId: string, userId: string, payload: {
452
+ role: AppMemberRole;
453
+ }): Promise<Json>;
439
454
  listOrganizationInvites(orgId: string): Promise<Json>;
440
455
  listProjectInvites(projectId: string): Promise<Json>;
441
456
  listAppInvites(appId: string): Promise<Json>;
package/dist/api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createApiClient
3
- } from "./chunk-R44EOUS4.js";
3
+ } from "./chunk-4276ARDF.js";
4
4
  import "./chunk-YZ34ICNN.js";
5
5
  export {
6
6
  createApiClient
@@ -0,0 +1,303 @@
1
+ import {
2
+ RemixError
3
+ } from "./chunk-YZ34ICNN.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 RemixError("API client is missing a token provider.", {
22
+ exitCode: 1,
23
+ hint: "Configure auth before creating the Remix 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 RemixError(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 RemixError("API client is missing a token provider.", {
54
+ exitCode: 1,
55
+ hint: "Configure auth before creating the Remix 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 RemixError(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
+ getOrganization: (orgId) => request(`/v1/organizations/${encodeURIComponent(orgId)}`, { method: "GET" }),
91
+ listProjects: (params) => {
92
+ const qs = new URLSearchParams();
93
+ if (params?.organizationId) qs.set("organizationId", params.organizationId);
94
+ if (params?.clientAppId) qs.set("clientAppId", params.clientAppId);
95
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
96
+ return request(`/v1/projects${suffix}`, { method: "GET" });
97
+ },
98
+ getProject: (projectId) => request(`/v1/projects/${encodeURIComponent(projectId)}`, { method: "GET" }),
99
+ resolveProjectBinding: (params) => {
100
+ const qs = new URLSearchParams();
101
+ if (params.repoFingerprint) qs.set("repoFingerprint", params.repoFingerprint);
102
+ if (params.remoteUrl) qs.set("remoteUrl", params.remoteUrl);
103
+ return request(`/v1/projects/bindings/resolve?${qs.toString()}`, { method: "GET" });
104
+ },
105
+ autoEnableDeveloper: () => request("/v1/developer/auto-enable", { method: "POST" }),
106
+ listClientApps: (params) => {
107
+ const qs = params?.orgId ? `?orgId=${encodeURIComponent(params.orgId)}` : "";
108
+ return request(`/v1/developer/client-apps${qs}`, { method: "GET" });
109
+ },
110
+ createClientApp: (payload) => request("/v1/developer/client-apps", { method: "POST", body: JSON.stringify(payload) }),
111
+ createClientAppKey: (clientAppId, payload) => request(`/v1/developer/client-apps/${encodeURIComponent(clientAppId)}/keys`, {
112
+ method: "POST",
113
+ body: JSON.stringify(payload ?? {})
114
+ }),
115
+ listApps: (params) => {
116
+ const qs = new URLSearchParams();
117
+ if (params?.projectId) qs.set("projectId", params.projectId);
118
+ if (params?.organizationId) qs.set("organizationId", params.organizationId);
119
+ if (params?.forked) qs.set("forked", params.forked);
120
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
121
+ return request(`/v1/apps${suffix}`, { method: "GET" });
122
+ },
123
+ getApp: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}`, { method: "GET" }),
124
+ getMergeRequest: (mrId) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}`, { method: "GET" }),
125
+ presignImportUpload: (payload) => request("/v1/apps/import/upload/presign", { method: "POST", body: JSON.stringify(payload) }),
126
+ importFromUpload: (payload) => request("/v1/apps/import/upload", { method: "POST", body: JSON.stringify(payload) }),
127
+ presignImportUploadFirstParty: (payload) => request("/v1/apps/import/upload/presign/first-party", { method: "POST", body: JSON.stringify(payload) }),
128
+ importFromUploadFirstParty: (payload) => request("/v1/apps/import/upload/first-party", { method: "POST", body: JSON.stringify(payload) }),
129
+ importFromGithubFirstParty: (payload) => request("/v1/apps/import/github/first-party", { method: "POST", body: JSON.stringify(payload) }),
130
+ forkApp: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/fork`, { method: "POST", body: JSON.stringify(payload ?? {}) }),
131
+ downloadAppBundle: (appId) => requestBinary(`/v1/apps/${encodeURIComponent(appId)}/download.bundle`, { method: "GET" }),
132
+ createChangeStep: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps`, {
133
+ method: "POST",
134
+ body: JSON.stringify(payload)
135
+ }),
136
+ createCollabTurn: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/collab-turns`, {
137
+ method: "POST",
138
+ body: JSON.stringify(payload)
139
+ }),
140
+ listCollabTurns: (appId, params) => {
141
+ const qs = new URLSearchParams();
142
+ if (params?.limit !== void 0) qs.set("limit", String(params.limit));
143
+ if (params?.offset !== void 0) qs.set("offset", String(params.offset));
144
+ if (params?.changeStepId) qs.set("changeStepId", params.changeStepId);
145
+ if (params?.threadId) qs.set("threadId", params.threadId);
146
+ if (params?.createdAfter) qs.set("createdAfter", params.createdAfter);
147
+ if (params?.createdBefore) qs.set("createdBefore", params.createdBefore);
148
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
149
+ return request(`/v1/apps/${encodeURIComponent(appId)}/collab-turns${suffix}`, { method: "GET" });
150
+ },
151
+ getCollabTurn: (appId, collabTurnId) => request(`/v1/apps/${encodeURIComponent(appId)}/collab-turns/${encodeURIComponent(collabTurnId)}`, {
152
+ method: "GET"
153
+ }),
154
+ getAgentMemorySummary: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/agent-memory/summary`, { method: "GET" }),
155
+ listAgentMemoryTimeline: (appId, params) => {
156
+ const qs = new URLSearchParams();
157
+ if (params?.limit !== void 0) qs.set("limit", String(params.limit));
158
+ if (params?.offset !== void 0) qs.set("offset", String(params.offset));
159
+ if (params?.createdAfter) qs.set("createdAfter", params.createdAfter);
160
+ if (params?.createdBefore) qs.set("createdBefore", params.createdBefore);
161
+ if (params?.kinds?.length) {
162
+ for (const kind of params.kinds) qs.append("kinds", kind);
163
+ }
164
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
165
+ return request(`/v1/apps/${encodeURIComponent(appId)}/agent-memory/timeline${suffix}`, { method: "GET" });
166
+ },
167
+ searchAgentMemory: (appId, params) => {
168
+ const qs = new URLSearchParams();
169
+ qs.set("q", params.q);
170
+ if (params.limit !== void 0) qs.set("limit", String(params.limit));
171
+ if (params.offset !== void 0) qs.set("offset", String(params.offset));
172
+ if (params.createdAfter) qs.set("createdAfter", params.createdAfter);
173
+ if (params.createdBefore) qs.set("createdBefore", params.createdBefore);
174
+ if (params.kinds?.length) {
175
+ for (const kind of params.kinds) qs.append("kinds", kind);
176
+ }
177
+ return request(`/v1/apps/${encodeURIComponent(appId)}/agent-memory/search?${qs.toString()}`, { method: "GET" });
178
+ },
179
+ getChangeStep: (appId, changeStepId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/${encodeURIComponent(changeStepId)}`, { method: "GET" }),
180
+ getChangeStepDiff: (appId, changeStepId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/${encodeURIComponent(changeStepId)}/diff`, {
181
+ method: "GET"
182
+ }),
183
+ startChangeStepReplay: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/replays`, {
184
+ method: "POST",
185
+ body: JSON.stringify(payload)
186
+ }),
187
+ getChangeStepReplay: (appId, replayId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/replays/${encodeURIComponent(replayId)}`, {
188
+ method: "GET"
189
+ }),
190
+ getChangeStepReplayDiff: (appId, replayId) => request(`/v1/apps/${encodeURIComponent(appId)}/change-steps/replays/${encodeURIComponent(replayId)}/diff`, {
191
+ method: "GET"
192
+ }),
193
+ listMergeRequests: (params) => {
194
+ const qs = new URLSearchParams();
195
+ if (params?.queue) qs.set("queue", params.queue);
196
+ if (params?.appId) qs.set("appId", params.appId);
197
+ if (params?.sourceAppId) qs.set("sourceAppId", params.sourceAppId);
198
+ if (params?.targetAppId) qs.set("targetAppId", params.targetAppId);
199
+ if (Array.isArray(params?.status)) {
200
+ for (const status of params.status) qs.append("status", status);
201
+ } else if (typeof params?.status === "string") {
202
+ qs.set("status", params.status);
203
+ }
204
+ if (params?.kind) qs.set("kind", params.kind);
205
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
206
+ return request(`/v1/merge-requests${suffix}`, { method: "GET" });
207
+ },
208
+ openMergeRequest: (sourceAppId) => request("/v1/merge-requests", { method: "POST", body: JSON.stringify({ sourceAppId }) }),
209
+ getMergeRequestReview: (mrId) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}/review`, { method: "GET" }),
210
+ updateMergeRequest: (mrId, payload) => request(`/v1/merge-requests/${encodeURIComponent(mrId)}`, { method: "PATCH", body: JSON.stringify(payload) }),
211
+ createOrganizationInvite: (orgId, payload) => request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations`, {
212
+ method: "POST",
213
+ body: JSON.stringify(payload)
214
+ }),
215
+ createProjectInvite: (projectId, payload) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations`, {
216
+ method: "POST",
217
+ body: JSON.stringify(payload)
218
+ }),
219
+ createAppInvite: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/invitations`, {
220
+ method: "POST",
221
+ body: JSON.stringify(payload)
222
+ }),
223
+ listOrganizationMembers: (orgId) => request(`/v1/organizations/${encodeURIComponent(orgId)}/members`, { method: "GET" }),
224
+ updateOrganizationMember: (orgId, userId, payload) => request(`/v1/organizations/${encodeURIComponent(orgId)}/members/${encodeURIComponent(userId)}`, {
225
+ method: "PATCH",
226
+ body: JSON.stringify(payload)
227
+ }),
228
+ listProjectMembers: (projectId) => request(`/v1/projects/${encodeURIComponent(projectId)}/members`, { method: "GET" }),
229
+ updateProjectMember: (projectId, userId, payload) => request(`/v1/projects/${encodeURIComponent(projectId)}/members/${encodeURIComponent(userId)}`, {
230
+ method: "PATCH",
231
+ body: JSON.stringify(payload)
232
+ }),
233
+ listAppMembers: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/members`, { method: "GET" }),
234
+ updateAppMember: (appId, userId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/members/${encodeURIComponent(userId)}`, {
235
+ method: "PATCH",
236
+ body: JSON.stringify(payload)
237
+ }),
238
+ listOrganizationInvites: (orgId) => request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations`, { method: "GET" }),
239
+ listProjectInvites: (projectId) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations`, { method: "GET" }),
240
+ listAppInvites: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/invitations`, { method: "GET" }),
241
+ resendOrganizationInvite: (orgId, inviteId, payload) => request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations/${encodeURIComponent(inviteId)}/resend`, {
242
+ method: "POST",
243
+ body: JSON.stringify(payload ?? {})
244
+ }),
245
+ resendProjectInvite: (projectId, inviteId, payload) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations/${encodeURIComponent(inviteId)}/resend`, {
246
+ method: "POST",
247
+ body: JSON.stringify(payload ?? {})
248
+ }),
249
+ resendAppInvite: (appId, inviteId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/invitations/${encodeURIComponent(inviteId)}/resend`, {
250
+ method: "POST",
251
+ body: JSON.stringify(payload ?? {})
252
+ }),
253
+ revokeOrganizationInvite: (orgId, inviteId) => request(`/v1/organizations/${encodeURIComponent(orgId)}/invitations/${encodeURIComponent(inviteId)}`, {
254
+ method: "DELETE"
255
+ }),
256
+ revokeProjectInvite: (projectId, inviteId) => request(`/v1/projects/${encodeURIComponent(projectId)}/invitations/${encodeURIComponent(inviteId)}`, {
257
+ method: "DELETE"
258
+ }),
259
+ revokeAppInvite: (appId, inviteId) => request(`/v1/apps/${encodeURIComponent(appId)}/invitations/${encodeURIComponent(inviteId)}`, {
260
+ method: "DELETE"
261
+ }),
262
+ syncUpstreamApp: (appId) => request(`/v1/apps/${encodeURIComponent(appId)}/sync-upstream`, {
263
+ method: "POST",
264
+ body: JSON.stringify({})
265
+ }),
266
+ preflightAppReconcile: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/preflight`, {
267
+ method: "POST",
268
+ body: JSON.stringify(payload)
269
+ }),
270
+ startAppReconcile: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/start`, {
271
+ method: "POST",
272
+ body: JSON.stringify(payload)
273
+ }),
274
+ getAppReconcile: (appId, reconcileId) => request(`/v1/apps/${encodeURIComponent(appId)}/reconcile/${encodeURIComponent(reconcileId)}`, { method: "GET" }),
275
+ downloadAppReconcileBundle: (appId, reconcileId) => requestBinary(`/v1/apps/${encodeURIComponent(appId)}/reconcile/${encodeURIComponent(reconcileId)}/download.bundle`, {
276
+ method: "GET"
277
+ }),
278
+ syncLocalApp: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/sync-local`, {
279
+ method: "POST",
280
+ body: JSON.stringify(payload)
281
+ }),
282
+ initiateBundle: (appId, payload) => request(`/v1/apps/${encodeURIComponent(appId)}/bundles`, { method: "POST", body: JSON.stringify(payload) }),
283
+ getBundle: (appId, bundleId) => request(`/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}`, { method: "GET" }),
284
+ getBundleDownloadUrl: (appId, bundleId, options) => request(
285
+ `/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}/download?redirect=${options?.redirect ?? false}`,
286
+ { method: "GET" }
287
+ ),
288
+ getBundleAssetsDownloadUrl: (appId, bundleId, options) => {
289
+ const qs = new URLSearchParams({
290
+ redirect: String(options?.redirect ?? false),
291
+ kind: options?.kind ?? "metro-assets"
292
+ });
293
+ return request(
294
+ `/v1/apps/${encodeURIComponent(appId)}/bundles/${encodeURIComponent(bundleId)}/assets/download?${qs.toString()}`,
295
+ { method: "GET" }
296
+ );
297
+ }
298
+ };
299
+ }
300
+
301
+ export {
302
+ createApiClient
303
+ };
@@ -0,0 +1,46 @@
1
+ import {
2
+ RemixError
3
+ } from "./chunk-YZ34ICNN.js";
4
+
5
+ // src/config/model.ts
6
+ import { z } from "zod";
7
+ var DEFAULT_API_URL = "http://localhost:3000";
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 RemixError("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
+ };