@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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/api.d.ts +494 -0
  4. package/dist/api.js +7 -0
  5. package/dist/auth.d.ts +27 -0
  6. package/dist/auth.js +15 -0
  7. package/dist/binding.d.ts +16 -0
  8. package/dist/binding.js +11 -0
  9. package/dist/chunk-2WGZS7CD.js +0 -0
  10. package/dist/chunk-34WDQCPF.js +242 -0
  11. package/dist/chunk-4OCNZHHR.js +0 -0
  12. package/dist/chunk-54CBEP2W.js +570 -0
  13. package/dist/chunk-55K5GHAZ.js +252 -0
  14. package/dist/chunk-5H5CZKGN.js +691 -0
  15. package/dist/chunk-5NTOJXEZ.js +223 -0
  16. package/dist/chunk-7WUKH3ZD.js +221 -0
  17. package/dist/chunk-AE2HPMUZ.js +80 -0
  18. package/dist/chunk-AEAOYVIL.js +200 -0
  19. package/dist/chunk-BJFCN2C3.js +46 -0
  20. package/dist/chunk-DCU3646I.js +12 -0
  21. package/dist/chunk-DEWAIK5X.js +11 -0
  22. package/dist/chunk-DRD6EVTT.js +447 -0
  23. package/dist/chunk-E4KAGBU7.js +134 -0
  24. package/dist/chunk-EF3677RE.js +93 -0
  25. package/dist/chunk-EVWDYCBL.js +223 -0
  26. package/dist/chunk-FAZUMWBS.js +93 -0
  27. package/dist/chunk-GC2MOT3U.js +12 -0
  28. package/dist/chunk-GFOBGYW4.js +252 -0
  29. package/dist/chunk-INDDXWAH.js +92 -0
  30. package/dist/chunk-K57ZFDGC.js +15 -0
  31. package/dist/chunk-NDA7EJJA.js +286 -0
  32. package/dist/chunk-NK2DA4X6.js +357 -0
  33. package/dist/chunk-OJMTW22J.js +286 -0
  34. package/dist/chunk-OMUDRPUI.js +195 -0
  35. package/dist/chunk-ONKKRS2C.js +239 -0
  36. package/dist/chunk-OWFBBWU7.js +196 -0
  37. package/dist/chunk-P7EM3N73.js +46 -0
  38. package/dist/chunk-PR5QKMHM.js +46 -0
  39. package/dist/chunk-RIP2MIZL.js +710 -0
  40. package/dist/chunk-TQHLFQY4.js +448 -0
  41. package/dist/chunk-TY3SSQQK.js +688 -0
  42. package/dist/chunk-UGKPOCN5.js +710 -0
  43. package/dist/chunk-VM3CGCNX.js +46 -0
  44. package/dist/chunk-XOQIADCH.js +223 -0
  45. package/dist/chunk-YZ34ICNN.js +17 -0
  46. package/dist/chunk-ZBMOGUSJ.js +17 -0
  47. package/dist/collab.d.ts +680 -0
  48. package/dist/collab.js +1917 -0
  49. package/dist/config.d.ts +22 -0
  50. package/dist/config.js +9 -0
  51. package/dist/errors.d.ts +21 -0
  52. package/dist/errors.js +12 -0
  53. package/dist/index.cjs +1269 -0
  54. package/dist/index.d.cts +482 -0
  55. package/dist/index.d.ts +6 -0
  56. package/dist/index.js +34 -0
  57. package/dist/repo.d.ts +66 -0
  58. package/dist/repo.js +62 -0
  59. package/dist/tokenProvider-BWTusyj4.d.ts +63 -0
  60. package/package.json +72 -0
@@ -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 = "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 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
+ };
@@ -0,0 +1,223 @@
1
+ import {
2
+ ComergeError
3
+ } from "./chunk-ZBMOGUSJ.js";
4
+
5
+ // src/auth/session.ts
6
+ import { z } from "zod";
7
+ var storedSessionSchema = z.object({
8
+ access_token: z.string().min(1),
9
+ refresh_token: z.string().min(1),
10
+ expires_at: z.number().int().positive(),
11
+ token_type: z.string().min(1).optional(),
12
+ user: z.object({
13
+ id: z.string().min(1),
14
+ email: z.string().email().optional().nullable()
15
+ }).optional()
16
+ });
17
+
18
+ // src/auth/localSessionStore.ts
19
+ import fs from "fs/promises";
20
+ import os from "os";
21
+ import path from "path";
22
+ function xdgConfigHome() {
23
+ const value = process.env.XDG_CONFIG_HOME;
24
+ if (typeof value === "string" && value.trim()) return value;
25
+ return path.join(os.homedir(), ".config");
26
+ }
27
+ async function maybeLoadKeytar() {
28
+ try {
29
+ const mod = await new Function("return import('keytar')")();
30
+ const candidates = [mod, mod?.default].filter(Boolean);
31
+ for (const candidate of candidates) {
32
+ const value = candidate;
33
+ if (typeof value.getPassword === "function" && typeof value.setPassword === "function") {
34
+ return value;
35
+ }
36
+ }
37
+ } catch {
38
+ return null;
39
+ }
40
+ return null;
41
+ }
42
+ async function ensurePathPermissions(filePath) {
43
+ const dir = path.dirname(filePath);
44
+ await fs.mkdir(dir, { recursive: true });
45
+ try {
46
+ await fs.chmod(dir, 448);
47
+ } catch {
48
+ }
49
+ try {
50
+ await fs.chmod(filePath, 384);
51
+ } catch {
52
+ }
53
+ }
54
+ async function writeJsonAtomic(filePath, value) {
55
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
56
+ const tmpPath = `${filePath}.tmp-${Date.now()}-${Math.random().toString(16).slice(2)}`;
57
+ await fs.writeFile(tmpPath, JSON.stringify(value, null, 2) + "\n", "utf8");
58
+ await fs.rename(tmpPath, filePath);
59
+ }
60
+ async function writeSessionFileFallback(filePath, session) {
61
+ await writeJsonAtomic(filePath, session);
62
+ await ensurePathPermissions(filePath);
63
+ }
64
+ function createLocalSessionStore(params) {
65
+ const service = params?.service?.trim() || "comerge-cli";
66
+ const account = params?.account?.trim() || "default";
67
+ const filePath = params?.filePath?.trim() || path.join(xdgConfigHome(), "comerge", "session.json");
68
+ return {
69
+ async getSession() {
70
+ const keytar = await maybeLoadKeytar();
71
+ if (keytar) {
72
+ const raw2 = await keytar.getPassword(service, account);
73
+ if (!raw2) return null;
74
+ try {
75
+ const parsed = storedSessionSchema.safeParse(JSON.parse(raw2));
76
+ return parsed.success ? parsed.data : null;
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
81
+ const raw = await fs.readFile(filePath, "utf8").catch(() => null);
82
+ if (!raw) return null;
83
+ try {
84
+ const parsed = storedSessionSchema.safeParse(JSON.parse(raw));
85
+ if (!parsed.success) return null;
86
+ await ensurePathPermissions(filePath);
87
+ return parsed.data;
88
+ } catch {
89
+ return null;
90
+ }
91
+ },
92
+ async setSession(session) {
93
+ const parsed = storedSessionSchema.safeParse(session);
94
+ if (!parsed.success) {
95
+ throw new Error("Session data is invalid and was not stored.");
96
+ }
97
+ const keytar = await maybeLoadKeytar();
98
+ if (keytar) {
99
+ await keytar.setPassword(service, account, JSON.stringify(parsed.data));
100
+ }
101
+ await writeSessionFileFallback(filePath, parsed.data);
102
+ }
103
+ };
104
+ }
105
+
106
+ // src/auth/tokenProvider.ts
107
+ function shouldRefreshSoon(session, skewSeconds = 60) {
108
+ const nowSec = Math.floor(Date.now() / 1e3);
109
+ return session.expires_at <= nowSec + skewSeconds;
110
+ }
111
+ function createStoredSessionTokenProvider(params) {
112
+ return async (opts) => {
113
+ const forceRefresh = Boolean(opts?.forceRefresh);
114
+ const envToken = process.env.COMERGE_ACCESS_TOKEN;
115
+ if (typeof envToken === "string" && envToken.trim().length > 0) {
116
+ return { token: envToken.trim(), session: null, fromEnv: true };
117
+ }
118
+ let session = await params.sessionStore.getSession();
119
+ if (!session) {
120
+ throw new ComergeError("Not signed in.", {
121
+ exitCode: 2,
122
+ hint: "Run `comerge login`, or set COMERGE_ACCESS_TOKEN for CI."
123
+ });
124
+ }
125
+ if (forceRefresh || shouldRefreshSoon(session)) {
126
+ try {
127
+ session = await params.refreshStoredSession({ config: params.config, session });
128
+ await params.sessionStore.setSession(session);
129
+ } catch (err) {
130
+ void err;
131
+ }
132
+ }
133
+ return { token: session.access_token, session, fromEnv: false };
134
+ };
135
+ }
136
+
137
+ // src/auth/supabase.ts
138
+ import { createClient } from "@supabase/supabase-js";
139
+ function createInMemoryStorage() {
140
+ const map = /* @__PURE__ */ new Map();
141
+ return {
142
+ getItem: (k) => map.get(k) ?? null,
143
+ setItem: (k, v) => {
144
+ map.set(k, v);
145
+ },
146
+ removeItem: (k) => {
147
+ map.delete(k);
148
+ }
149
+ };
150
+ }
151
+ function createSupabaseClient(config, storage) {
152
+ return createClient(config.supabaseUrl, config.supabaseAnonKey, {
153
+ auth: {
154
+ flowType: "pkce",
155
+ persistSession: false,
156
+ autoRefreshToken: false,
157
+ detectSessionInUrl: false,
158
+ storage
159
+ },
160
+ global: {
161
+ headers: {
162
+ "X-Requested-By": "comerge-cli"
163
+ }
164
+ }
165
+ });
166
+ }
167
+ function toStoredSession(session) {
168
+ if (!session.access_token || !session.refresh_token || !session.expires_at) {
169
+ throw new ComergeError("Supabase session is missing required fields.", { exitCode: 1 });
170
+ }
171
+ return {
172
+ access_token: session.access_token,
173
+ refresh_token: session.refresh_token,
174
+ expires_at: session.expires_at,
175
+ token_type: session.token_type ?? void 0,
176
+ user: session.user ? { id: session.user.id, email: session.user.email ?? null } : void 0
177
+ };
178
+ }
179
+ function createSupabaseAuthHelpers(config) {
180
+ const storage = createInMemoryStorage();
181
+ const supabase = createSupabaseClient(config, storage);
182
+ return {
183
+ async startGoogleLogin(params) {
184
+ const { data, error } = await supabase.auth.signInWithOAuth({
185
+ provider: "google",
186
+ options: {
187
+ redirectTo: params.redirectTo,
188
+ skipBrowserRedirect: true,
189
+ queryParams: {
190
+ access_type: "offline",
191
+ prompt: "consent"
192
+ }
193
+ }
194
+ });
195
+ if (error) throw error;
196
+ if (!data?.url) throw new ComergeError("Supabase did not return an OAuth URL.", { exitCode: 1 });
197
+ return { url: data.url };
198
+ },
199
+ async exchangeCode(params) {
200
+ const { data, error } = await supabase.auth.exchangeCodeForSession(params.code);
201
+ if (error) throw error;
202
+ if (!data?.session) throw new ComergeError("Supabase did not return a session.", { exitCode: 1 });
203
+ return toStoredSession(data.session);
204
+ },
205
+ async refreshWithStoredSession(params) {
206
+ const { data, error } = await supabase.auth.setSession({
207
+ access_token: params.session.access_token,
208
+ refresh_token: params.session.refresh_token
209
+ });
210
+ if (error) throw error;
211
+ if (!data?.session) throw new ComergeError("No session returned after refresh.", { exitCode: 1 });
212
+ return toStoredSession(data.session);
213
+ }
214
+ };
215
+ }
216
+
217
+ export {
218
+ storedSessionSchema,
219
+ createLocalSessionStore,
220
+ shouldRefreshSoon,
221
+ createStoredSessionTokenProvider,
222
+ createSupabaseAuthHelpers
223
+ };
@@ -0,0 +1,17 @@
1
+ // src/errors/cliError.ts
2
+ var RemixError = class extends Error {
3
+ code;
4
+ exitCode;
5
+ hint;
6
+ constructor(message, opts) {
7
+ super(message);
8
+ this.name = "RemixError";
9
+ this.code = opts?.code ?? null;
10
+ this.exitCode = opts?.exitCode ?? 1;
11
+ this.hint = opts?.hint ?? null;
12
+ }
13
+ };
14
+
15
+ export {
16
+ RemixError
17
+ };
@@ -0,0 +1,17 @@
1
+ // src/errors/cliError.ts
2
+ var ComergeError = class extends Error {
3
+ code;
4
+ exitCode;
5
+ hint;
6
+ constructor(message, opts) {
7
+ super(message);
8
+ this.name = "ComergeError";
9
+ this.code = opts?.code ?? null;
10
+ this.exitCode = opts?.exitCode ?? 1;
11
+ this.hint = opts?.hint ?? null;
12
+ }
13
+ };
14
+
15
+ export {
16
+ ComergeError
17
+ };