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