@lupinum/ginko-server 0.0.0-stage → 0.18.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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +176 -2
- package/convex/_generated/api.d.ts +185 -0
- package/convex/_generated/api.js +23 -0
- package/convex/_generated/dataModel.d.ts +60 -0
- package/convex/_generated/server.d.ts +162 -0
- package/convex/_generated/server.js +101 -0
- package/convex/account.ts +110 -0
- package/convex/agent.ts +814 -0
- package/convex/auth.config.ts +4 -0
- package/convex/auth.ts +62 -0
- package/convex/backup.ts +94 -0
- package/convex/betterAuth/_generated/api.ts +56 -0
- package/convex/betterAuth/_generated/component.ts +431 -0
- package/convex/betterAuth/_generated/dataModel.ts +60 -0
- package/convex/betterAuth/_generated/server.ts +169 -0
- package/convex/betterAuth/adapter.ts +7 -0
- package/convex/betterAuth/convex.config.ts +3 -0
- package/convex/betterAuth/schema.ts +102 -0
- package/convex/betterAuth/schemaMetadata.ts +697 -0
- package/convex/betterAuth/schemaOptions.ts +13 -0
- package/convex/betterAuth/schemaPlugins.ts +13 -0
- package/convex/bundle.ts +183 -0
- package/convex/changes.ts +136 -0
- package/convex/cleanup.ts +44 -0
- package/convex/connect.ts +143 -0
- package/convex/convex.config.ts +7 -0
- package/convex/crons.ts +14 -0
- package/convex/demo.ts +72 -0
- package/convex/entries.ts +1770 -0
- package/convex/facts.ts +129 -0
- package/convex/files.ts +631 -0
- package/convex/http.ts +21 -0
- package/convex/image.ts +45 -0
- package/convex/images.ts +54 -0
- package/convex/invites.ts +227 -0
- package/convex/lib/access.ts +180 -0
- package/convex/lib/agentTools.ts +331 -0
- package/convex/lib/content.ts +317 -0
- package/convex/lib/corpus.ts +83 -0
- package/convex/lib/diff.ts +50 -0
- package/convex/lib/fail.ts +27 -0
- package/convex/lib/files.ts +70 -0
- package/convex/lib/history.ts +103 -0
- package/convex/lib/i18n.ts +52 -0
- package/convex/lib/input.ts +57 -0
- package/convex/lib/library.ts +28 -0
- package/convex/lib/lifecycle.ts +100 -0
- package/convex/lib/list.ts +112 -0
- package/convex/lib/migrations.ts +126 -0
- package/convex/lib/names.ts +56 -0
- package/convex/lib/pending.ts +84 -0
- package/convex/lib/policy.ts +155 -0
- package/convex/lib/publicness.ts +87 -0
- package/convex/lib/reminders.ts +27 -0
- package/convex/lib/search.ts +132 -0
- package/convex/lib/siteUrl.ts +95 -0
- package/convex/lib/status.ts +109 -0
- package/convex/lib/translation.ts +56 -0
- package/convex/lib/trees.ts +43 -0
- package/convex/lib/write.ts +296 -0
- package/convex/mail.ts +136 -0
- package/convex/members.ts +129 -0
- package/convex/migrations.ts +105 -0
- package/convex/navigation.ts +276 -0
- package/convex/ops.ts +50 -0
- package/convex/proposals.ts +753 -0
- package/convex/refresh.ts +163 -0
- package/convex/release.ts +435 -0
- package/convex/reminders.ts +116 -0
- package/convex/retention.ts +121 -0
- package/convex/routes/bundle.ts +62 -0
- package/convex/routes/connect.ts +80 -0
- package/convex/routes/export.ts +23 -0
- package/convex/routes/file.ts +34 -0
- package/convex/routes/key.ts +53 -0
- package/convex/routes/mcp.ts +300 -0
- package/convex/routes/release.ts +66 -0
- package/convex/routes/upload.ts +94 -0
- package/convex/schema.ts +443 -0
- package/convex/search.ts +58 -0
- package/convex/seed.ts +624 -0
- package/convex/siteDeletion.ts +78 -0
- package/convex/sites.ts +393 -0
- package/convex/tasks.ts +51 -0
- package/convex/tsconfig.json +27 -0
- package/convex/uploads.ts +429 -0
- package/convex/uploadsNode.ts +86 -0
- package/convex/views.ts +111 -0
- package/i18n/de.json +364 -0
- package/i18n/en.json +364 -0
- package/i18n/es.json +364 -0
- package/i18n/fr.json +364 -0
- package/package.json +45 -3
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
actionGeneric,
|
|
13
|
+
httpActionGeneric,
|
|
14
|
+
queryGeneric,
|
|
15
|
+
mutationGeneric,
|
|
16
|
+
internalActionGeneric,
|
|
17
|
+
internalMutationGeneric,
|
|
18
|
+
internalQueryGeneric,
|
|
19
|
+
} from "convex/server";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Define a query in this Convex app's public API.
|
|
23
|
+
*
|
|
24
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
25
|
+
*
|
|
26
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
27
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
28
|
+
*/
|
|
29
|
+
export const query = queryGeneric;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
33
|
+
*
|
|
34
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
35
|
+
*
|
|
36
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
37
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
38
|
+
*/
|
|
39
|
+
export const internalQuery = internalQueryGeneric;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Define a mutation in this Convex app's public API.
|
|
43
|
+
*
|
|
44
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
45
|
+
*
|
|
46
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
47
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
48
|
+
*/
|
|
49
|
+
export const mutation = mutationGeneric;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
53
|
+
*
|
|
54
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
55
|
+
*
|
|
56
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
57
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
58
|
+
*/
|
|
59
|
+
export const internalMutation = internalMutationGeneric;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Define an action in this Convex app's public API.
|
|
63
|
+
*
|
|
64
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
65
|
+
* code and code with side-effects, like calling third-party services.
|
|
66
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
67
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
68
|
+
*
|
|
69
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
70
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
71
|
+
*/
|
|
72
|
+
export const action = actionGeneric;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
76
|
+
*
|
|
77
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
78
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
79
|
+
*/
|
|
80
|
+
export const internalAction = internalActionGeneric;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Define an HTTP action.
|
|
84
|
+
*
|
|
85
|
+
* The wrapped function will be used to respond to HTTP requests received
|
|
86
|
+
* by a Convex deployment if the requests matches the path and method where
|
|
87
|
+
* this action is routed. Be sure to route your httpAction in `convex/http.js`.
|
|
88
|
+
*
|
|
89
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument
|
|
90
|
+
* and a Fetch API `Request` object as its second.
|
|
91
|
+
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
92
|
+
*/
|
|
93
|
+
export const httpAction = httpActionGeneric;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Typesafe environment variables.
|
|
97
|
+
*
|
|
98
|
+
* This includes platform-provided env vars and any variables declared in
|
|
99
|
+
* `convex.config.ts`.
|
|
100
|
+
*/
|
|
101
|
+
export const env = process.env;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// A person's own settings (SPEC 10). Not tied to a site: one switch for all their sites.
|
|
2
|
+
import { v } from 'convex/values'
|
|
3
|
+
import { components } from './_generated/api'
|
|
4
|
+
import { mutation, query } from './_generated/server'
|
|
5
|
+
import { currentUser, fail } from './lib/access'
|
|
6
|
+
import { isLocale } from './lib/i18n'
|
|
7
|
+
import { normalizeEmail } from './members'
|
|
8
|
+
|
|
9
|
+
/** Reminder mail is on unless the person switched it off. `locale` and `name` are null until they chose one. */
|
|
10
|
+
export const settings = query({
|
|
11
|
+
args: {},
|
|
12
|
+
handler: async (ctx) => {
|
|
13
|
+
const user = await currentUser(ctx)
|
|
14
|
+
const row = await ctx.db.query('userSettings').withIndex('by_user', (q) => q.eq('user', user.id)).unique()
|
|
15
|
+
return { remindByMail: row?.remindByMail ?? true, locale: row?.locale ?? null, name: row?.name ?? null }
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const PERSON_NAME_MAX = 60
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The name every team of this person sees instead of their email (`lib/names.ts`), staff included. One per person,
|
|
23
|
+
* set by the person. An empty name removes it, and the teams see the email again.
|
|
24
|
+
*/
|
|
25
|
+
export const setName = mutation({
|
|
26
|
+
args: { name: v.string() },
|
|
27
|
+
handler: async (ctx, args): Promise<null> => {
|
|
28
|
+
const user = await currentUser(ctx)
|
|
29
|
+
const name = args.name.trim().replace(/\s+/g, ' ')
|
|
30
|
+
if (name.length > PERSON_NAME_MAX) fail('INVALID', 'errors.nameTooLong', { nameMax: PERSON_NAME_MAX })
|
|
31
|
+
const row = await ctx.db.query('userSettings').withIndex('by_user', (q) => q.eq('user', user.id)).unique()
|
|
32
|
+
if (row) await ctx.db.patch(row._id, { name: name || undefined })
|
|
33
|
+
else if (name) await ctx.db.insert('userSettings', { user: user.id, remindByMail: true, name })
|
|
34
|
+
return null
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export const setRemindByMail = mutation({
|
|
39
|
+
args: { on: v.boolean() },
|
|
40
|
+
handler: async (ctx, args): Promise<null> => {
|
|
41
|
+
const user = await currentUser(ctx)
|
|
42
|
+
const row = await ctx.db.query('userSettings').withIndex('by_user', (q) => q.eq('user', user.id)).unique()
|
|
43
|
+
if (row) await ctx.db.patch(row._id, { remindByMail: args.on })
|
|
44
|
+
else await ctx.db.insert('userSettings', { user: user.id, remindByMail: args.on })
|
|
45
|
+
return null
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/** The language the Studio showed this person while they have chosen none (for mails only; see schema `seenLocale`). */
|
|
50
|
+
export const sawLocale = mutation({
|
|
51
|
+
args: { locale: v.string() },
|
|
52
|
+
handler: async (ctx, args): Promise<null> => {
|
|
53
|
+
const user = await currentUser(ctx)
|
|
54
|
+
if (!isLocale(args.locale)) return null
|
|
55
|
+
const row = await ctx.db.query('userSettings').withIndex('by_user', (q) => q.eq('user', user.id)).unique()
|
|
56
|
+
if (!row) await ctx.db.insert('userSettings', { user: user.id, remindByMail: true, seenLocale: args.locale })
|
|
57
|
+
else if (row.seenLocale !== args.locale) await ctx.db.patch(row._id, { seenLocale: args.locale })
|
|
58
|
+
return null
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
/** The language of the messages and mail this person gets: one of the catalogs in `i18n/`. */
|
|
63
|
+
export const setLocale = mutation({
|
|
64
|
+
args: { locale: v.string() },
|
|
65
|
+
handler: async (ctx, args): Promise<null> => {
|
|
66
|
+
const user = await currentUser(ctx)
|
|
67
|
+
if (!isLocale(args.locale)) fail('INVALID', 'errors.languageUnsupported', { locale: args.locale })
|
|
68
|
+
const row = await ctx.db.query('userSettings').withIndex('by_user', (q) => q.eq('user', user.id)).unique()
|
|
69
|
+
if (row) await ctx.db.patch(row._id, { locale: args.locale })
|
|
70
|
+
else await ctx.db.insert('userSettings', { user: user.id, remindByMail: true, locale: args.locale })
|
|
71
|
+
return null
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Deletes the signed-in person's account (GDPR). Refused while they are the last owner of a site that is not
|
|
77
|
+
* already being deleted; the message names the sites. Otherwise it removes their memberships, the invitations to their address,
|
|
78
|
+
* their agent keys, saved views and settings, and the Better Auth user with its sessions and accounts (so they are signed out).
|
|
79
|
+
* Rows that only name them (history, proposals, uploads) stay: the id points to nothing any more, and the Studio shows
|
|
80
|
+
* "Former member" for it (`lib/names.ts`). No name or address is kept.
|
|
81
|
+
*/
|
|
82
|
+
export const deleteAccount = mutation({
|
|
83
|
+
args: {},
|
|
84
|
+
handler: async (ctx): Promise<null> => {
|
|
85
|
+
const user = await currentUser(ctx)
|
|
86
|
+
const memberships = await ctx.db.query('memberships').withIndex('by_user_site', (q) => q.eq('user', user.id)).collect()
|
|
87
|
+
|
|
88
|
+
const blocking: string[] = []
|
|
89
|
+
for (const member of memberships.filter((m) => m.role === 'owner')) {
|
|
90
|
+
const site = await ctx.db.get(member.site)
|
|
91
|
+
if (!site || site.deleting) continue
|
|
92
|
+
const owners = (await ctx.db.query('memberships').withIndex('by_site', (q) => q.eq('site', member.site)).collect()).filter((m) => m.role === 'owner')
|
|
93
|
+
if (owners.length <= 1) blocking.push(site.name)
|
|
94
|
+
}
|
|
95
|
+
if (blocking.length) fail('INVALID', 'errors.lastOwnerOfSites', { sites: blocking.join(', ') }, { sites: blocking })
|
|
96
|
+
|
|
97
|
+
for (const member of memberships) await ctx.db.delete(member._id)
|
|
98
|
+
if (user.email) {
|
|
99
|
+
for (const invite of await ctx.db.query('invites').withIndex('by_email', (q) => q.eq('email', normalizeEmail(user.email!))).collect()) await ctx.db.delete(invite._id)
|
|
100
|
+
}
|
|
101
|
+
for (const key of await ctx.db.query('agentKeys').withIndex('by_user', (q) => q.eq('user', user.id)).collect()) await ctx.db.delete(key._id)
|
|
102
|
+
for (const view of await ctx.db.query('views').withIndex('by_user', (q) => q.eq('user', user.id)).collect()) await ctx.db.delete(view._id)
|
|
103
|
+
for (const row of await ctx.db.query('userSettings').withIndex('by_user', (q) => q.eq('user', user.id)).collect()) await ctx.db.delete(row._id)
|
|
104
|
+
for (const row of await ctx.db.query('admins').withIndex('by_user', (q) => q.eq('user', user.id)).collect()) await ctx.db.delete(row._id)
|
|
105
|
+
|
|
106
|
+
// The user row cascades to its sessions and accounts (Better Auth schema metadata). Done last: `currentUser` reads it.
|
|
107
|
+
await ctx.runMutation(components.betterAuth.adapter.deleteOne, { model: 'user', where: [{ field: 'id', value: user.id }] })
|
|
108
|
+
return null
|
|
109
|
+
},
|
|
110
|
+
})
|