-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing internal actions and a command to run them
- Loading branch information
1 parent
6e94996
commit fb1c6d3
Showing
27 changed files
with
1,671 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import prisma from '~/server/prisma' | ||
export default async function findUsers(query: string) { | ||
return prisma.user.findMany({ | ||
where: { | ||
OR: [ | ||
{ | ||
firstName: { | ||
mode: 'insensitive', | ||
contains: query, | ||
}, | ||
}, | ||
{ | ||
lastName: { | ||
mode: 'insensitive', | ||
contains: query, | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { MenuItem } from '@interval/sdk/dist/types' | ||
import { Organization, OrganizationSSO } from '@prisma/client' | ||
|
||
export default function orgRowMenuItems( | ||
row: Organization & { sso?: Pick<OrganizationSSO, 'id'> | null } | ||
): MenuItem[] { | ||
return [ | ||
{ | ||
label: 'Browse app structure', | ||
action: 'organizations/app_structure', | ||
params: { org: row.slug }, | ||
}, | ||
{ | ||
label: 'Change slug', | ||
action: 'organizations/change_slug', | ||
params: { org: row.slug }, | ||
}, | ||
{ | ||
label: 'Enable SSO', | ||
action: 'organizations/create_org_sso', | ||
params: { org: row.slug }, | ||
}, | ||
{ | ||
label: 'Disable SSO', | ||
action: 'organizations/disable_org_sso', | ||
params: { org: row.slug }, | ||
disabled: row.sso === null, | ||
}, | ||
{ | ||
label: 'Toggle feature flag', | ||
action: 'organizations/org_feature_flag', | ||
params: { org: row.slug }, | ||
}, | ||
{ | ||
label: 'Transfer owner', | ||
action: 'organizations/transfer_ownership', | ||
params: { org: row.slug }, | ||
}, | ||
{ | ||
label: 'Create transaction history export', | ||
action: 'organizations/create_transaction_history_export', | ||
params: { org: row.slug }, | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { User } from '@prisma/client' | ||
|
||
export default function renderUserResult(user: User) { | ||
return { | ||
label: [user.firstName, user.lastName].join(' '), | ||
description: user.email, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ctx } from '@interval/sdk' | ||
import prisma from '~/server/prisma' | ||
import selectOrganization from './selectOrganization' | ||
|
||
export default async function requireOrg(paramName = 'org') { | ||
if (paramName in ctx.params) { | ||
const org = await prisma.organization.findFirst({ | ||
where: { slug: String(ctx.params[paramName]) }, | ||
include: { | ||
sso: true, | ||
environments: true, | ||
}, | ||
}) | ||
|
||
if (!org) throw new Error('Org not found') | ||
|
||
return org | ||
} | ||
|
||
return selectOrganization() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ctx } from '@interval/sdk' | ||
|
||
export default function requireParam(key: string) { | ||
if (ctx.params[key] === undefined) { | ||
throw new Error(`Missing required param: ${key}`) | ||
} | ||
|
||
return String(ctx.params[key]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { io } from '@interval/sdk' | ||
import { Prisma } from '@prisma/client' | ||
|
||
import prisma from '~/server/prisma' | ||
|
||
export default async function searchForOrganization() { | ||
return io.search<Prisma.OrganizationGetPayload<{ include: { owner: true } }>>( | ||
'Select organization', | ||
{ | ||
async onSearch(query) { | ||
return prisma.organization.findMany({ | ||
where: { | ||
OR: [ | ||
{ | ||
name: { | ||
search: query, | ||
mode: 'insensitive', | ||
}, | ||
}, | ||
{ | ||
name: { | ||
contains: query, | ||
mode: 'insensitive', | ||
}, | ||
}, | ||
], | ||
}, | ||
include: { | ||
owner: true, | ||
}, | ||
}) | ||
}, | ||
renderResult: org => ({ | ||
value: org.id, | ||
label: org.name, | ||
description: `Owner: ${org.owner.firstName} ${org.owner.lastName} (${org.owner.email}), Slug: ${org.slug}`, | ||
}), | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import prisma from '~/server/prisma' | ||
import searchForOrganization from './searchForOrganization' | ||
|
||
export default async function selectOrganization() { | ||
const selected = await searchForOrganization() | ||
|
||
const org = await prisma.organization.findUnique({ | ||
where: { | ||
id: selected.id, | ||
}, | ||
include: { | ||
sso: true, | ||
environments: true, | ||
}, | ||
}) | ||
|
||
if (!org) { | ||
throw new Error("Organization doesn't exist?") | ||
} | ||
|
||
return org | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { io } from '@interval/sdk' | ||
import findUsers from './findUsers' | ||
import renderUserResult from './renderUserResult' | ||
|
||
export default function selectUser() { | ||
return io.search('Select a user', { | ||
onSearch: async q => await findUsers(q), | ||
renderResult: renderUserResult, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Don't use this with any query strings that aren't static | ||
|
||
import { io } from '@interval/sdk' | ||
import prisma from '~/server/prisma' | ||
|
||
export default async function staticQuery(query: string) { | ||
const rows: Record<string, string>[] = await prisma.$queryRawUnsafe(query) | ||
await io.display.table('Rows', { data: rows }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import path from 'path' | ||
import { Interval } from '@interval/sdk' | ||
import env from '../env' | ||
|
||
if (!env.INTERVAL_KEY) { | ||
throw new Error( | ||
'Environment variable INTERVAL_KEY required for internal actions.' | ||
) | ||
} | ||
|
||
const interval = new Interval({ | ||
endpoint: `${env.APP_URL}/websocket`, | ||
apiKey: env.INTERVAL_KEY, | ||
routesDirectory: path.resolve(__dirname, 'routes'), | ||
}) | ||
|
||
interval.listen() |
Oops, something went wrong.