Skip to content
← Public packages

@kentcdodds/devin

Start, monitor, and manage Devin sessions, knowledge, playbooks, and schedules via the Devin v3 API

src/settings.ts

39 lines · 1.1 KB · TypeScript
import {
	migrateDevinFromValues,
	readDevinOrgId,
	writeDevinOrgId,
} from './lib/client.ts'

export { migrateDevinFromValues, readDevinOrgId, writeDevinOrgId }

/**
 * Read or update Devin package settings. Pass `orgId` to persist a new org
 * id in this package's storage (no republish). Omit fields to read.
 *
 * @param input.orgId - Devin org id to persist; omit to read the current settings.
 * @returns Current `{ orgId }` when reading, or `{ updated, settings }` when writing.
 *
 * @example
 * import destSettings from 'kody:@kentcdodds/devin/settings'
 * const current = await destSettings()
 * // => { orgId: '...' }
 */
export default async function destSettings(
	input: { orgId?: string } = {},
) {
	const orgId = typeof input?.orgId === 'string' ? input.orgId.trim() : ''
	if (orgId) {
		await writeDevinOrgId(orgId)
		return {
			updated: ['orgId'],
			settings: await readDevinSettings(),
		}
	}
	return await readDevinSettings()
}

/** Read the current Devin org id from package storage. */
export async function readDevinSettings() {
	const orgId = await readDevinOrgId()
	return { orgId: orgId || null }
}