docs(liveshare-protocol): keep identity providers out of the protocol package

The identity contract and its fixtures named specific providers even though the package only describes the abstract triple. The JSDocs now say a deployment's adapter implements it, and every fixture and spec uses the neutral example provider while keeping the encoding, round-trip, and empty-field cases they pin.
This commit is contained in:
mektpoy committed 2026-10-23 16:13:22 +08:00
1 parent 590826f66d
commit f1aca0df84
7 files changed
+22 -22

No files matched your search

@@ -38,7 +38,7 @@ export function identityFromKey(key: string): IdentityTriple | undefined {
/**
* Tenant id recorded for a provider that issues no tenant of its own, such as a
* DeepSeek account adapter. Providers that own a tenant must reject an empty
* An account adapter whose provider issues no tenant of its own must reject an empty
* tenant instead of using this placeholder; see {@link requireIdentityTenant}.
*/
export const IDENTITY_TENANT_PLACEHOLDER = 'default'
@@ -32,7 +32,7 @@ export interface IdentityExchangeRequest {
readonly redirectUri: string
}
/** Generic browser OAuth contract implemented by Feishu and local mocks. */
/** Generic browser OAuth contract a deployment's identity adapter implements; the protocol's mock implements it for local runs. */
export interface IdentityProvider {
readonly id: string
readonly scopes: readonly string[]
@@ -10,7 +10,7 @@
"body": {}
},
"actor": {
"providerId": "feishu",
"providerId": "example",
"tenantId": "tenant-a",
"subjectId": "ou_viewer"
}
@@ -11,7 +11,7 @@
"relay": "wss://relay.example",
"gatewayToken": "token-one",
"ownerDisplayName": "Owner",
"allowedSubjectIds": ["ou_viewer", "feishu:tenant-a:ou_other"],
"allowedSubjectIds": ["ou_viewer", "example:tenant-a:user-other"],
"sessionMode": "write",
"allowsFork": true,
"allowsFileUpload": true,
@@ -5,7 +5,7 @@
"type": "share-rpc",
"id": 7,
"body": { "op": "call", "path": "/__share/context", "body": {} },
"actor": { "providerId": "feishu", "tenantId": "tenant-a", "subjectId": "ou_viewer" }
"actor": { "providerId": "example", "tenantId": "tenant-a", "subjectId": "ou_viewer" }
},
"required": ["id", "body", "actor"],
"optional": []
@@ -6,7 +6,7 @@
"id": 7,
"shareId": "share-one",
"body": { "op": "stream-open", "id": 1, "endpoint": "trajectory", "payload": {} },
"actor": { "providerId": "feishu", "tenantId": "tenant-a", "subjectId": "ou_viewer" }
"actor": { "providerId": "example", "tenantId": "tenant-a", "subjectId": "ou_viewer" }
},
"required": ["type", "id", "shareId", "actor"],
"optional": ["body"]
@@ -9,7 +9,7 @@ import {
} from '@deepseek-ai/dsh-experimental-liveshare-protocol/identity'
const actor: IdentityActor = {
providerId: 'feishu',
providerId: 'example',
tenantId: 'tenant/a',
subjectId: 'user:one',
displayName: 'Alice',
@@ -17,7 +17,7 @@ const actor: IdentityActor = {
describe('identity keys', () => {
it('derives one stable, encoded identity key from the provider triple', () => {
expect(identityKeyOf(actor)).toBe('feishu:tenant%2Fa:user%3Aone')
expect(identityKeyOf(actor)).toBe('example:tenant%2Fa:user%3Aone')
expect(identityKeyOf(actor)).toBe(identityKeyOf({
providerId: actor.providerId,
tenantId: actor.tenantId,
@@ -28,28 +28,28 @@ describe('identity keys', () => {
tenantId: actor.tenantId,
subjectId: actor.subjectId,
})
expect(identityFromKey('feishu:only-two')).toBeUndefined()
expect(identityFromKey('feishu:%E0%A4%A:user')).toBeUndefined()
expect(identityFromKey('example:only-two')).toBeUndefined()
expect(identityFromKey('example:%E0%A4%A:user')).toBeUndefined()
})
it('fills the placeholder tenant only for a provider that issues none', () => {
expect(normalizeIdentity({ providerId: 'deepseek', tenantId: '', subjectId: 'user' }))
.toEqual({ providerId: 'deepseek', tenantId: IDENTITY_TENANT_PLACEHOLDER, subjectId: 'user' })
expect(normalizeIdentity({ providerId: 'deepseek', tenantId: 'tenant-a', subjectId: 'user' }))
.toEqual({ providerId: 'deepseek', tenantId: 'tenant-a', subjectId: 'user' })
expect(normalizeIdentity({ providerId: 'example', tenantId: '', subjectId: 'user' }))
.toEqual({ providerId: 'example', tenantId: IDENTITY_TENANT_PLACEHOLDER, subjectId: 'user' })
expect(normalizeIdentity({ providerId: 'example', tenantId: 'tenant-a', subjectId: 'user' }))
.toEqual({ providerId: 'example', tenantId: 'tenant-a', subjectId: 'user' })
expect(normalizeIdentity({ providerId: '', tenantId: '', subjectId: 'user' })).toBeUndefined()
expect(normalizeIdentity({ providerId: 'deepseek', tenantId: '', subjectId: '' })).toBeUndefined()
expect(normalizeIdentity({ providerId: 'deepseek', tenantId: '', subjectId: 'user' }, ''))
expect(normalizeIdentity({ providerId: 'example', tenantId: '', subjectId: '' })).toBeUndefined()
expect(normalizeIdentity({ providerId: 'example', tenantId: '', subjectId: 'user' }, ''))
.toBeUndefined()
expect(normalizeIdentity({ providerId: 'deepseek', tenantId: '', subjectId: 'user' }, 'tenant-b'))
.toEqual({ providerId: 'deepseek', tenantId: 'tenant-b', subjectId: 'user' })
expect(normalizeIdentity({ providerId: 'example', tenantId: '', subjectId: 'user' }, 'tenant-b'))
.toEqual({ providerId: 'example', tenantId: 'tenant-b', subjectId: 'user' })
})
it('rejects any triple whose provider must issue a tenant but left it empty', () => {
expect(requireIdentityTenant({ providerId: 'feishu', tenantId: 'tenant-a', subjectId: 'user' }))
.toEqual({ providerId: 'feishu', tenantId: 'tenant-a', subjectId: 'user' })
expect(requireIdentityTenant({ providerId: 'feishu', tenantId: '', subjectId: 'user' })).toBeUndefined()
expect(requireIdentityTenant({ providerId: 'example', tenantId: 'tenant-a', subjectId: 'user' }))
.toEqual({ providerId: 'example', tenantId: 'tenant-a', subjectId: 'user' })
expect(requireIdentityTenant({ providerId: 'example', tenantId: '', subjectId: 'user' })).toBeUndefined()
expect(requireIdentityTenant({ providerId: '', tenantId: 'tenant-a', subjectId: 'user' })).toBeUndefined()
expect(requireIdentityTenant({ providerId: 'feishu', tenantId: 'tenant-a', subjectId: '' })).toBeUndefined()
expect(requireIdentityTenant({ providerId: 'example', tenantId: 'tenant-a', subjectId: '' })).toBeUndefined()
})
})