mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
feat(core): say which credential changed in credential.updated (#62762)
This commit is contained in:
committed by
GitHub
Unverified
parent
6973d89bf5
commit
6aef6aa81e
+1
-1
@@ -1678,7 +1678,7 @@ export type CredentialUpdated = {
|
||||
metadata?: { [x: string]: any }
|
||||
type: "credential.updated"
|
||||
location?: LocationRef
|
||||
data: {}
|
||||
data: { integrationID: IntegrationID; credentialID: CredentialID }
|
||||
}
|
||||
|
||||
export type CredentialSwitched = {
|
||||
|
||||
@@ -191,7 +191,11 @@ const layer = Layer.effect(
|
||||
type: credential.value.type,
|
||||
active: activated,
|
||||
})
|
||||
yield* bus.publish(Event.Updated, {}, { global: true })
|
||||
yield* bus.publish(
|
||||
Event.Updated,
|
||||
{ integrationID: credential.integrationID, credentialID: credential.id },
|
||||
{ global: true },
|
||||
)
|
||||
if (activated)
|
||||
yield* bus.publish(
|
||||
Event.Switched,
|
||||
@@ -249,7 +253,11 @@ const layer = Layer.effect(
|
||||
labelChanged: updates.label !== undefined && updates.label !== credential.label,
|
||||
})
|
||||
if (updates.label !== undefined && updates.label !== credential.label)
|
||||
yield* bus.publish(Event.Updated, {}, { global: true })
|
||||
yield* bus.publish(
|
||||
Event.Updated,
|
||||
{ integrationID: credential.integrationID, credentialID: id },
|
||||
{ global: true },
|
||||
)
|
||||
}),
|
||||
remove: Effect.fn("Credential.remove")(function* (id) {
|
||||
const removed = yield* db
|
||||
@@ -283,7 +291,12 @@ const layer = Layer.effect(
|
||||
active: removed.switched,
|
||||
...(removed.switched ? { replacementID: removed.credentialID } : {}),
|
||||
})
|
||||
yield* bus.publish(Event.Updated, {}, { global: true })
|
||||
if (removed.integrationID)
|
||||
yield* bus.publish(
|
||||
Event.Updated,
|
||||
{ integrationID: removed.integrationID, credentialID: id },
|
||||
{ global: true },
|
||||
)
|
||||
if (removed.switched)
|
||||
yield* bus.publish(
|
||||
Event.Switched,
|
||||
|
||||
@@ -119,18 +119,18 @@ describe("Credential", () => {
|
||||
expect(yield* credentials.list(integrationID)).toEqual([])
|
||||
|
||||
expect(events.map((event) => ({ type: event.type, data: event.data }))).toEqual([
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: older.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: older.id } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: newer.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: newer.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: older.id } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: older.id } },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: newer.id } },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: replacement.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: replacement.id } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: replacement.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: older.id } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: older.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: null } },
|
||||
])
|
||||
expect(events.every((event) => !("location" in event))).toBeTrue()
|
||||
@@ -178,8 +178,8 @@ describe("Credential", () => {
|
||||
.pipe(Effect.orDie),
|
||||
).toEqual({ active: true })
|
||||
expect(events.map((event) => ({ type: event.type, data: event.data }))).toEqual([
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: oldest.id } },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: newest.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: newer.id } },
|
||||
])
|
||||
}),
|
||||
@@ -260,11 +260,11 @@ describe("Credential", () => {
|
||||
|
||||
expect(yield* credentials.list(integrationID)).toEqual([first, imported, legacy])
|
||||
expect(events.map((event) => ({ type: event.type, data: event.data }))).toEqual([
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: first.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: first.id } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: legacy.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { integrationID, credentialID: legacy.id } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: imported.id } },
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -179,7 +179,7 @@ describe("Integration", () => {
|
||||
}),
|
||||
])
|
||||
expect((yield* Fiber.join(created)).map((event) => ({ type: event.type, data: event.data }))).toEqual([
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: stored[0]?.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { credentialID: stored[0]?.id, integrationID } },
|
||||
])
|
||||
}),
|
||||
@@ -635,7 +635,7 @@ describe("Integration", () => {
|
||||
yield* integrations.connection.remove(archived.id)
|
||||
expect(events).toEqual([
|
||||
{ type: Credential.Event.Switched.type, data: { credentialID: work.id, integrationID } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: archived.id } },
|
||||
])
|
||||
|
||||
yield* integrations.connection.remove(work.id)
|
||||
@@ -652,10 +652,10 @@ describe("Integration", () => {
|
||||
})
|
||||
expect(events).toEqual([
|
||||
{ type: Credential.Event.Switched.type, data: { credentialID: work.id, integrationID } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: archived.id } },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: work.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { credentialID: personal.id, integrationID } },
|
||||
{ type: Credential.Event.Updated.type, data: {} },
|
||||
{ type: Credential.Event.Updated.type, data: { integrationID, credentialID: personal.id } },
|
||||
{ type: Credential.Event.Switched.type, data: { credentialID: null, integrationID } },
|
||||
])
|
||||
}),
|
||||
|
||||
Generated
+11
-3
@@ -26292,9 +26292,17 @@
|
||||
"$ref": "#/components/schemas/Location.Ref"
|
||||
},
|
||||
"data": {
|
||||
"not": {
|
||||
"type": "null"
|
||||
}
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"integrationID": {
|
||||
"$ref": "#/components/schemas/Integration.ID"
|
||||
},
|
||||
"credentialID": {
|
||||
"$ref": "#/components/schemas/Credential.ID"
|
||||
}
|
||||
},
|
||||
"required": ["integrationID", "credentialID"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["id", "created", "type", "data"],
|
||||
|
||||
@@ -14,9 +14,10 @@ export const ID = Schema.String.pipe(
|
||||
)
|
||||
export type ID = typeof ID.Type
|
||||
|
||||
// A login was added, renamed or removed. Every change is to exactly one credential.
|
||||
const Updated = ephemeral({
|
||||
type: "credential.updated",
|
||||
schema: {},
|
||||
schema: { integrationID: IntegrationID, credentialID: ID },
|
||||
})
|
||||
const Switched = ephemeral({
|
||||
type: "credential.switched",
|
||||
|
||||
@@ -87,7 +87,7 @@ describe("public event manifest", () => {
|
||||
expect(EventManifest.Durable.has(definition.type)).toBe(false)
|
||||
}
|
||||
|
||||
expect(Credential.Event.Updated.data.make({})).toEqual({})
|
||||
expect(Credential.Event.Updated.data.make({ integrationID, credentialID })).toEqual({ integrationID, credentialID })
|
||||
expect(Credential.Event.Switched.data.make({ integrationID, credentialID })).toEqual({
|
||||
integrationID,
|
||||
credentialID,
|
||||
|
||||
@@ -398,7 +398,12 @@ async function renderIntegration(activeLocation?: LocationRef, form?: FormFields
|
||||
const body = (await request.json()) as { label: string }
|
||||
accounts = accounts.map((account) => (account.id === id ? { ...account, label: body.label } : account))
|
||||
requests.push({ method: request.method, path: url.pathname, body })
|
||||
events.emit({ id: `evt_updated_${id}`, created: Date.now(), type: "credential.updated", data: {} })
|
||||
events.emit({
|
||||
id: `evt_updated_${id}`,
|
||||
created: Date.now(),
|
||||
type: "credential.updated",
|
||||
data: { integrationID: "openai", credentialID: id },
|
||||
})
|
||||
return new Response(null, { status: 204 })
|
||||
}
|
||||
|
||||
@@ -407,7 +412,12 @@ async function renderIntegration(activeLocation?: LocationRef, form?: FormFields
|
||||
const active = accounts[0]?.id === id
|
||||
accounts = accounts.filter((account) => account.id !== id)
|
||||
requests.push({ method: request.method, path: url.pathname })
|
||||
events.emit({ id: `evt_deleted_${id}`, created: Date.now(), type: "credential.updated", data: {} })
|
||||
events.emit({
|
||||
id: `evt_deleted_${id}`,
|
||||
created: Date.now(),
|
||||
type: "credential.updated",
|
||||
data: { integrationID: "openai", credentialID: id },
|
||||
})
|
||||
if (active)
|
||||
events.emit({
|
||||
id: `evt_switched_${id}`,
|
||||
|
||||
@@ -3601,7 +3601,7 @@ describe("V2 mini transport", () => {
|
||||
id: "evt_credential.updated",
|
||||
created: 0,
|
||||
type: "credential.updated",
|
||||
data: {},
|
||||
data: { integrationID: "openai", credentialID: "credential" },
|
||||
})
|
||||
for (const credentialID of ["credential", null])
|
||||
events.push({
|
||||
|
||||
Reference in New Issue
Block a user