( token: McpSessionInit, storedMeta: SessionMeta | null, )
| 188 | * base Durable Object only offers a matching one), or `null`. |
| 189 | */ |
| 190 | export const resolveSessionMetaForToken = ( |
| 191 | token: McpSessionInit, |
| 192 | storedMeta: SessionMeta | null, |
| 193 | ): Effect.Effect< |
| 194 | SessionMeta, |
| 195 | McpSessionMetaUnavailableError | OrganizationNotFoundError, |
| 196 | UserStoreService | WorkOSClient |
| 197 | > => |
| 198 | Effect.gen(function* () { |
| 199 | const fromProps = token.organizationName; |
| 200 | if (fromProps) { |
| 201 | yield* Effect.annotateCurrentSpan(SESSION_META_SOURCE_ATTRIBUTE, "props"); |
| 202 | return metaFromIdentity(token, { name: fromProps, slug: token.organizationSlug }); |
| 203 | } |
| 204 | |
| 205 | if (storedMeta?.organizationName) { |
| 206 | yield* Effect.annotateCurrentSpan(SESSION_META_SOURCE_ATTRIBUTE, "stored"); |
| 207 | return metaFromIdentity(token, { |
| 208 | name: storedMeta.organizationName, |
| 209 | slug: storedMeta.organizationSlug, |
| 210 | }); |
| 211 | } |
| 212 | |
| 213 | yield* Effect.annotateCurrentSpan(SESSION_META_SOURCE_ATTRIBUTE, "database"); |
| 214 | const organization = yield* organizationFromDatabase(token.organizationId); |
| 215 | return metaFromIdentity(token, organization); |
| 216 | }); |
no test coverage detected