{"version":3,"file":"index.mjs","names":["isClient","createClient","isClient","createClient"],"sources":["../src/domains/authorize/constants.ts","../src/utils/has-own-property.ts","../src/utils/scope.ts","../src/domains/authorize/helper.ts","../src/domains/base.ts","../src/domains/authorize/module.ts","../src/domains/token/utils/header-transformation.ts","../src/domains/token/utils/request-transformation.ts","../src/domains/token/module.ts","../src/domains/userinfo/index.ts","../src/module.ts","../src/instance.ts","../src/constants.ts","../src/open-id/provider-metadata.ts","../src/open-id/client.ts","../src/open-id/url.ts","../src/index.ts"],"sourcesContent":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum AuthorizeResponseMode {\n    QUERY = 'query',\n    FRAGMENT = 'fragment',\n    FORM_POST = 'form_post',\n    WEB_MESSAGE = 'web_message',\n}\n\nexport enum AuthorizeCodeChallengeMethod {\n    SHA_256 = 'S256',\n    PLAIN = 'plain',\n}\n\nexport enum AuthorizeResponseType {\n    NONE = 'none',\n    CODE = 'code',\n    TOKEN = 'token',\n    ID_TOKEN = 'id_token',\n}\n","/*\n * Copyright (c) 2021.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n    return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function scopeToArray(scope: string[] | string) : string[] {\n    return Array.isArray(scope) ?\n        scope :\n        scope.split(' ');\n}\n\nexport function scopeToString(scope: string[] | string) : string {\n    if (typeof scope === 'string') {\n        return scope;\n    }\n\n    return [\n        ...new Set(scope),\n    ].join(' ');\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { scopeToString } from '../../utils';\nimport type { AuthorizeParameters } from './types';\n\nexport function buildAuthorizeURL(\n    url: string,\n    parameters: AuthorizeParameters,\n) : string {\n    const output = new URL(url);\n\n    if (parameters.response_type) {\n        output.searchParams.set(\n            'response_type',\n            Array.isArray(parameters.response_type) ?\n                scopeToString(parameters.response_type) :\n                parameters.response_type,\n        );\n    } else {\n        output.searchParams.set('response_type', 'code');\n    }\n\n    if (parameters.client_id) {\n        output.searchParams.set('client_id', parameters.client_id);\n    }\n\n    if (parameters.redirect_uri) {\n        output.searchParams.set('redirect_uri', parameters.redirect_uri);\n    }\n\n    if (parameters.response_mode) {\n        output.searchParams.set('response_mode', parameters.response_mode);\n    }\n\n    if (parameters.scope) {\n        const scope = Array.isArray(parameters.scope) ?\n            scopeToString(parameters.scope) :\n            parameters.scope;\n\n        output.searchParams.set('scope', scope);\n    }\n\n    if (parameters.state) {\n        output.searchParams.set('state', parameters.state);\n    }\n\n    if (parameters.code_challenge) {\n        output.searchParams.set('code_challenge', parameters.code_challenge);\n    }\n\n    if (parameters.code_challenge_method) {\n        output.searchParams.set('code_challenge_method', parameters.code_challenge_method);\n    }\n\n    return output.href;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createClient, isClient } from 'hapic';\nimport type { IClient, RequestBaseOptions } from 'hapic';\nimport type { Options } from '../config';\nimport type { BaseAPIContext } from './type';\n\nexport abstract class BaseAPI {\n    protected client! : IClient;\n\n    protected options!: Options;\n\n    // -----------------------------------------------------------------------------------\n\n    constructor(context: BaseAPIContext = {}) {\n        this.setClient(context.client);\n        this.setOptions(context.options);\n    }\n\n    // -----------------------------------------------------------------------------------\n\n    setClient(input?: IClient | RequestBaseOptions) {\n        this.client = isClient(input) ?\n            input :\n            createClient(input);\n    }\n\n    setOptions(options?: Options) {\n        this.options = options || {};\n    }\n\n    setOption<K extends keyof Options>(key: K, value: Options[K]) {\n        this.options[key] = value;\n    }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildAuthorizeURL } from './helper';\nimport type { AuthorizeParameters } from './types';\nimport { BaseAPI } from '../base';\n\nexport class AuthorizeAPI extends BaseAPI {\n    /**\n     * Build authorize url based on\n     * input parameters.\n     *\n     * @param parameters\n     */\n    buildURL(parameters: Partial<AuthorizeParameters> = {}) : string {\n        let baseURL : string;\n\n        if (this.options.authorizationEndpoint) {\n            baseURL = this.options.authorizationEndpoint;\n        } else {\n            const clientURL = this.client.defaults.baseURL;\n\n            baseURL = new URL('authorize', clientURL).href;\n        }\n\n        return buildAuthorizeURL(baseURL, {\n            ...parameters,\n            redirect_uri: parameters.redirect_uri || this.options.redirectUri,\n            client_id: parameters.client_id || this.options.clientId,\n            scope: parameters.scope || this.options.scope,\n            response_type: parameters.response_type || 'code',\n        });\n    }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport { stringifyAuthorizationHeader } from 'hapic';\nimport type { TokenBaseOptions } from '../type';\n\n/**\n * Set Content-Type and Authorization Header for request.\n *\n * @param headers\n * @param options\n */\nexport function transformHeadersForTokenAPIRequest(\n    headers: Headers,\n    options: TokenBaseOptions = {},\n) : void {\n    // set content type\n    headers.set('Content-Type', 'application/x-www-form-urlencoded');\n\n    if (\n        options.authorizationHeaderInherit &&\n        headers.has('Authorization')\n    ) {\n        return;\n    }\n\n    // request should be in general unauthorized\n    headers.delete('Authorization');\n\n    if (options.authorizationHeader) {\n        const header = typeof options.authorizationHeader === 'string' ?\n            options.authorizationHeader :\n            stringifyAuthorizationHeader(options.authorizationHeader);\n\n        headers.set('Authorization', header);\n\n        return;\n    }\n\n    if (\n        options.clientCredentialsAsHeader &&\n        options.clientId &&\n        options.clientSecret\n    ) {\n        headers.set('Authorization', stringifyAuthorizationHeader({\n            type: 'Basic',\n            username: options.clientId,\n            password: options.clientSecret,\n        }));\n    }\n}\n","/*\n * Copyright (c) 2023-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from 'hapic';\nimport type { RequestTransformer } from 'hapic';\nimport type { ClientAuthenticationParameters, TokenBaseOptions } from '../type';\nimport { transformHeadersForTokenAPIRequest } from './header-transformation';\n\nexport function createRequestTransformerForTokenAPIRequest(\n    parameters: ClientAuthenticationParameters,\n    options: TokenBaseOptions = {},\n) : RequestTransformer {\n    return (data: any, headers: Headers) => {\n        if (!options.clientId) {\n            options.clientId = parameters.client_id;\n            options.clientSecret = parameters.client_secret;\n        }\n\n        if (!options.realmId) {\n            options.realmId = parameters.realm_id;\n        }\n\n        transformHeadersForTokenAPIRequest(headers, options);\n\n        if (options.clientCredentialsAsHeader) {\n            if (data instanceof URLSearchParams) {\n                data.delete('client_id');\n                data.delete('client_secret');\n\n                return data;\n            }\n\n            if (isObject(data)) {\n                if (typeof data.client_id !== 'undefined') {\n                    delete data.client_id;\n                }\n\n                if (typeof data.client_secret !== 'undefined') {\n                    delete data.client_secret;\n                }\n            }\n        }\n\n        return data;\n    };\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { RequestTransformer } from 'hapic';\nimport { HeaderName } from 'hapic';\nimport type { JwtPayload } from '../../type';\n\nimport { BaseAPI } from '../base';\nimport type {\n    ClientAuthenticationParameters,\n    TokenAuthorizationCodeGrantParameters,\n    TokenBaseOptions,\n    TokenClientCredentialsGrantParameters,\n    TokenGrantParameters,\n    TokenGrantResponse,\n    TokenIntrospectParameters,\n    TokenPasswordGrantParameters,\n    TokenRefreshTokenGrantParameters,\n    TokenRevokeParameters,\n    TokenRobotCredentialsGrantParameters,\n} from './type';\nimport { createRequestTransformerForTokenAPIRequest } from './utils';\n\nexport class TokenAPI extends BaseAPI {\n    async createWithRefreshToken(\n        parameters: Omit<TokenRefreshTokenGrantParameters, 'grant_type'>,\n        options?: TokenBaseOptions,\n    ) {\n        return this.create({\n            grant_type: 'refresh_token',\n            ...parameters,\n        }, options);\n    }\n\n    async createWithClientCredentials(\n        parameters: Omit<TokenClientCredentialsGrantParameters, 'grant_type'> = {},\n        options: TokenBaseOptions = {},\n    ) {\n        return this.create({\n            grant_type: 'client_credentials',\n            ...parameters,\n        }, options);\n    }\n\n    async createWithPassword(\n        parameters: Omit<TokenPasswordGrantParameters, 'grant_type'>,\n        options: TokenBaseOptions = {},\n    ) {\n        return this.create({\n            grant_type: 'password',\n            ...parameters,\n        }, options);\n    }\n\n    async createWithAuthorizationCode(\n        parameters: Omit<TokenAuthorizationCodeGrantParameters, 'grant_type'>,\n        options: TokenBaseOptions = {},\n    ): Promise<TokenGrantResponse> {\n        return this.create({\n            grant_type: 'authorization_code',\n            ...parameters,\n        }, options);\n    }\n\n    async createWithRobotCredentials(\n        parameters: Omit<TokenRobotCredentialsGrantParameters, 'grant_type'>,\n        options: TokenBaseOptions = {},\n    ) {\n        return this.create({\n            grant_type: 'robot_credentials',\n            ...parameters,\n        }, options);\n    }\n\n    // ------------------------------------------------------------------\n\n    /**\n     * @throws Error\n     * @param parameters\n     * @param options\n     */\n    async create(\n        parameters: TokenGrantParameters,\n        options: TokenBaseOptions = {},\n    ): Promise<TokenGrantResponse> {\n        this.extendCreateParameters(parameters);\n\n        const urlSearchParams = this.buildURLSearchParams(parameters);\n\n        const { data } = await this.client.post(\n            (this.options.tokenEndpoint || '/token'),\n            urlSearchParams,\n            {\n                transform: this.buildRequestTransformers(parameters, options),\n                headers: { [HeaderName.ACCEPT]: 'application/json' },\n            },\n        );\n\n        const tokenResponse: TokenGrantResponse = {\n            access_token: data.access_token,\n            expires_in: data.expires_in,\n            token_type: data.token_type || 'Bearer',\n        };\n\n        if (data.refresh_token) {\n            tokenResponse.refresh_token = data.refresh_token;\n        }\n\n        if (typeof data.refresh_token_expires_in === 'number') {\n            tokenResponse.refresh_token_expires_in = data.refresh_token_expires_in;\n        }\n\n        if (typeof data.id_token === 'string') {\n            tokenResponse.id_token = data.id_token;\n        }\n\n        if (typeof data.mac_key === 'string') {\n            tokenResponse.mac_key = data.mac_key;\n        }\n\n        if (typeof data.mac_algorithm === 'string') {\n            tokenResponse.mac_algorithm = data.mac_algorithm;\n        }\n\n        return tokenResponse;\n    }\n\n    async revoke(\n        parameters: TokenRevokeParameters = {},\n        options: TokenBaseOptions = {},\n    ) {\n        const urlSearchParams = this.buildURLSearchParams(parameters);\n\n        return this.client.post(\n            (this.options.revocationEndpoint || '/token/revoke'),\n            urlSearchParams,\n            {\n                transform: this.buildRequestTransformers(parameters, options),\n                headers: { [HeaderName.ACCEPT]: 'application/json' },\n            },\n        );\n    }\n\n    async introspect<T extends JwtPayload>(\n        parameters: TokenIntrospectParameters = {},\n        options: TokenBaseOptions = {},\n    ): Promise<T> {\n        const urlSearchParams = this.buildURLSearchParams(parameters);\n\n        const { data } = await this.client.post(\n            this.options.introspectionEndpoint || '/token/introspect',\n            urlSearchParams,\n            {\n                transform: this.buildRequestTransformers(parameters, options),\n                headers: { [HeaderName.ACCEPT]: 'application/json' },\n            },\n        );\n\n        return data;\n    }\n\n    protected buildRequestTransformers(\n        parameters: ClientAuthenticationParameters,\n        options: TokenBaseOptions = {},\n    ) : RequestTransformer[] {\n        const transformers : RequestTransformer[] = [];\n\n        if (!options.clientId) {\n            if (this.options.clientId) {\n                options.clientId = this.options.clientId;\n            }\n\n            if (this.options.clientSecret) {\n                options.clientSecret = this.options.clientSecret;\n            }\n        }\n\n        if (!options.realmId && this.options.realmId) {\n            options.realmId = this.options.realmId;\n        }\n\n        transformers.push(createRequestTransformerForTokenAPIRequest(parameters, options));\n\n        if (this.client.defaults.transform) {\n            if (Array.isArray(this.client.defaults.transform)) {\n                transformers.push(...this.client.defaults.transform);\n            } else {\n                transformers.push(this.client.defaults.transform);\n            }\n        }\n\n        return transformers;\n    }\n\n    // ------------------------------------------------------------------\n\n    extendCreateParameters(parameters: TokenGrantParameters): TokenGrantParameters {\n        if (\n            parameters.grant_type !== 'authorization_code' &&\n            parameters.grant_type !== 'robot_credentials'\n        ) {\n            if (!parameters.scope && this.options.scope) {\n                parameters.scope = this.options.scope;\n            }\n        }\n\n        if (parameters.grant_type === 'authorization_code') {\n            if (!parameters.redirect_uri && this.options.redirectUri) {\n                parameters.redirect_uri = this.options.redirectUri;\n            }\n        }\n\n        if (!parameters.client_id) {\n            if (parameters.client_secret) {\n                delete parameters.client_secret;\n            }\n\n            if (this.options.clientId) {\n                parameters.client_id = this.options.clientId;\n            }\n\n            if (this.options.clientSecret) {\n                parameters.client_secret = this.options.clientSecret;\n            }\n        }\n\n        if (!parameters.realm_id && this.options.realmId) {\n            parameters.realm_id = this.options.realmId;\n        }\n\n        return parameters;\n    }\n\n    // ------------------------------------------------------------------\n\n    protected buildURLSearchParams(\n        input: Record<string, any>,\n    ) : URLSearchParams {\n        const urlSearchParams = new URLSearchParams();\n        const keys = Object.keys(input);\n        for (const key of keys) {\n            const value = input[key];\n\n            if (typeof value === 'string' && !!value) {\n                urlSearchParams.append(key, value);\n            } else if (Array.isArray(value)) {\n                const str = value.filter((el) => el).join(' ');\n                if (str) {\n                    urlSearchParams.append(key, str);\n                }\n            }\n        }\n\n        return urlSearchParams;\n    }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { AuthorizationHeader } from 'hapic';\nimport { HeaderName, stringifyAuthorizationHeader } from 'hapic';\nimport { BaseAPI } from '../base';\nimport type { BaseAPIContext } from '../type';\n\nexport class UserInfoAPI extends BaseAPI {\n    constructor(context?: BaseAPIContext) {\n        super(context);\n    }\n\n    // -----------------------------------------------------------------------------------\n\n    /**\n     * @throws Error\n     * @param header\n     */\n    async get<T extends Record<string, any> = Record<string, any>>(\n        header?: string | AuthorizationHeader,\n    ) : Promise<T> {\n        const headers : Record<string, string> = { [HeaderName.ACCEPT]: 'application/json' };\n\n        if (header) {\n            if (typeof header === 'string') {\n                if (!header.includes(' ')) {\n                    headers.Authorization = `Bearer ${header}`;\n                } else {\n                    headers.Authorization = header;\n                }\n            } else {\n                headers.Authorization = stringifyAuthorizationHeader(header);\n            }\n        }\n\n        const { data } = await this.client.get(\n            (this.options.userinfoEndpoint || '/userinfo'),\n            { headers },\n        );\n\n        return data;\n    }\n}\n","/*\n * Copyright (c) 2021-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Client, markInstanceof } from 'hapic';\nimport type { ConfigInput, Options } from './config';\n\nimport { AuthorizeAPI, TokenAPI, UserInfoAPI } from './domains';\n\nexport const OAUTH2_CLIENT_INSTANCE = Symbol.for('@hapic/oauth2/OAuth2Client');\n\nexport class OAuth2Client extends Client {\n    public readonly options : Options;\n\n    public authorize: AuthorizeAPI;\n\n    public token : TokenAPI;\n\n    public userInfo : UserInfoAPI;\n\n    // -----------------------------------------------------------------------------------\n\n    constructor(input: ConfigInput = {}) {\n        super(input.request);\n\n        markInstanceof(this, OAUTH2_CLIENT_INSTANCE);\n\n        const options = input.options || {};\n\n        this.options = options;\n\n        this.token = new TokenAPI({ client: this, options });\n        this.authorize = new AuthorizeAPI({ client: this, options });\n        this.userInfo = new UserInfoAPI({ client: this, options });\n    }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createClientRegistry } from 'hapic';\nimport type { ConfigInput } from './config';\nimport { OAUTH2_CLIENT_INSTANCE, OAuth2Client } from './module';\n\nexport const {\n    hasClient,\n    setClient,\n    useClient,\n    unsetClient,\n    createClient,\n    isClient,\n} = createClientRegistry<OAuth2Client, ConfigInput>({\n    create: (input) => new OAuth2Client(input),\n    id: OAUTH2_CLIENT_INSTANCE,\n});\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum ResponseType {\n    NONE = 'none',\n    CODE = 'code',\n    ID_TOKEN = 'id_token',\n    TOKEN = 'token',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport type { Options } from '../config';\nimport type { OpenIDProviderMetadata } from './type';\n\nexport function parseOpenIDProviderMetadata(\n    data: OpenIDProviderMetadata,\n) : Options {\n    const options: Options = {};\n\n    if (data.authorization_endpoint) {\n        options.authorizationEndpoint = data.authorization_endpoint;\n    }\n\n    if (data.introspection_endpoint) {\n        options.introspectionEndpoint = data.introspection_endpoint;\n    }\n\n    if (data.token_endpoint) {\n        options.tokenEndpoint = data.token_endpoint;\n    }\n\n    if (data.userinfo_endpoint) {\n        options.userinfoEndpoint = data.userinfo_endpoint;\n    }\n\n    if (data.revocation_endpoint) {\n        options.revocationEndpoint = data.revocation_endpoint;\n    }\n\n    return options;\n}\n","/*\n * Copyright (c) 2023-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IClient, RequestBaseOptions } from 'hapic';\nimport { createClient, isClient } from 'hapic';\nimport { OAuth2Client } from '../module';\nimport { parseOpenIDProviderMetadata } from './provider-metadata';\nimport type { OpenIDProviderMetadata } from './type';\n\n/**\n * Create a client instance by requesting details of\n * the open-id discovery endpoint.\n *\n * @param url (.e.g. .well-known/openid-configuration)\n * @param options\n */\nexport async function createClientWithOpenIDDiscoveryURL(\n    url: string,\n    options?: IClient | RequestBaseOptions,\n) : Promise<OAuth2Client> {\n    let client: IClient;\n\n    if (isClient(options)) {\n        client = options;\n    } else {\n        client = createClient(options);\n    }\n\n    const { data }: { data: OpenIDProviderMetadata } = await client.get(url);\n\n    return new OAuth2Client({\n        request: client.defaults,\n        options: parseOpenIDProviderMetadata(data),\n    });\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function buildOpenIDDiscoveryURL(baseURL?: string) : string {\n    let url = '.well-known/openid-configuration';\n\n    if (baseURL) {\n        url = new URL(url, baseURL).href;\n    } else {\n        url = `/${url}`;\n    }\n\n    return url;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createClient } from './instance';\n\nexport * from './config';\nexport * from './client';\nexport * from './constants';\nexport * from './instance';\nexport * from './domains';\nexport * from './open-id';\nexport * from './module';\nexport * from './type';\nexport * from './utils';\n\nconst client = createClient();\nexport default client;\n"],"mappings":";;AAOA,IAAY,wBAAL,yBAAA,uBAAA;CACH,sBAAA,WAAA;CACA,sBAAA,cAAA;CACA,sBAAA,eAAA;CACA,sBAAA,iBAAA;;AACJ,EAAA,CAAA,CAAA;AAEA,IAAY,+BAAL,yBAAA,8BAAA;CACH,6BAAA,aAAA;CACA,6BAAA,WAAA;;AACJ,EAAA,CAAA,CAAA;AAEA,IAAY,wBAAL,yBAAA,uBAAA;CACH,sBAAA,UAAA;CACA,sBAAA,UAAA;CACA,sBAAA,WAAA;CACA,sBAAA,cAAA;;AACJ,EAAA,CAAA,CAAA;;;ACjBA,SAAgB,eAAoD,KAAQ,MAAwC;CAChH,OAAO,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI;AACzD;;;ACFA,SAAgB,aAAa,OAAqC;CAC9D,OAAO,MAAM,QAAQ,KAAK,IACtB,QACA,MAAM,MAAM,GAAG;AACvB;AAEA,SAAgB,cAAc,OAAmC;CAC7D,IAAI,OAAO,UAAU,UACjB,OAAO;CAGX,OAAO,CACH,GAAG,IAAI,IAAI,KAAK,CACpB,CAAC,CAAC,KAAK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