207 lines
8.0 KiB
TypeScript
207 lines
8.0 KiB
TypeScript
// Metro module 13547 (f13548).
|
|
import ConnectedAccountsStore from "../../../../stores/ConnectedAccountsStore";
|
|
import * as _Constants from "../../Constants";
|
|
import { PlatformTypes, ComponentActions, AnalyticsLocations } from "../../../../Constants";
|
|
import * as _Constants3 from "../../../activities/Constants";
|
|
import { RPCCommands, RPCErrors } from "../../../../_bundle/Module505";
|
|
import createRpcJoiSchemaObject from "../../helpers/createRpcJoiSchemaObject";
|
|
import { validatePostMessageTransport, validateApplication } from "../../RPCHelpers";
|
|
import Platforms from "../../../../lib/Platforms";
|
|
import RPCError from "../../RPCError";
|
|
import Dispatcher from "../../../../Dispatcher";
|
|
import { ComponentDispatch } from "../../../../utils/ComponentDispatchUtils";
|
|
import authorizeConnection_native from "../../../connections/authorizeConnection.native";
|
|
import ConnectedAccountsActionCreators from "../../../../actions/ConnectedAccountsActionCreators";
|
|
let c9406_3;
|
|
let env9406 = {};
|
|
const { RPC_AUTHENTICATED_SCOPE, RPC_SCOPE_CONFIG } = _Constants;
|
|
const { AM_HARMONY_PRD_APPLICATION_ID, AM_HARMONY_STG_APPLICATION_ID } = _Constants3;
|
|
const c9406_10 = new Set([AM_HARMONY_PRD_APPLICATION_ID, AM_HARMONY_STG_APPLICATION_ID]);
|
|
const r44 = {};
|
|
const GET_PROVIDER_ACCESS_TOKEN = RPCCommands.GET_PROVIDER_ACCESS_TOKEN;
|
|
const scope = {};
|
|
scope[RPC_SCOPE_CONFIG.ANY] = [RPC_AUTHENTICATED_SCOPE];
|
|
r44[GET_PROVIDER_ACCESS_TOKEN] = {
|
|
scope,
|
|
validation: (a0) => createRpcJoiSchemaObject(a0).required().keys({
|
|
provider: a0.string().required(),
|
|
connection_redirect: a0.string()
|
|
}),
|
|
handler: (a0) => {
|
|
let env20525 = {
|
|
$parent: env9406
|
|
};
|
|
const { socket, args } = a0;
|
|
const provider = args.provider;
|
|
env20525[0] = provider;
|
|
env20525[1] = args.connection_redirect;
|
|
env20525[2] = void 0;
|
|
validatePostMessageTransport(socket.transport);
|
|
const r23 = validateApplication(socket.application);
|
|
const r28 = Platforms.get(provider);
|
|
env20525[2] = r28;
|
|
if (r28 == null) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.INVALID_PROVIDER
|
|
}, `Platform not found for provider "${provider}"`);
|
|
}
|
|
if (provider !== PlatformTypes.AMAZON_MUSIC) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.UNAUTHORIZED_FOR_APPLICATION
|
|
}, "Command not available for this application");
|
|
}
|
|
if (c9406_10.has(r23)) {
|
|
const r43 = Promise;
|
|
let c20526_0 = async (c30639_0, c30639_1) => {
|
|
let c30639_2, c30639_3, c30639_4;
|
|
let c30639_5 = 0;
|
|
const r13 = void 0;
|
|
const r12 = env20525;
|
|
L16: {
|
|
L14: {
|
|
try {
|
|
let env31690;
|
|
c30639_3 = r13;
|
|
const r32 = env31690 = {
|
|
$parent: r12
|
|
};
|
|
c30639_2 = r32;
|
|
env31690[0] = c30639_0;
|
|
env31690[1] = c30639_1;
|
|
env31690[2] = void 0;
|
|
const account = ConnectedAccountsStore.getAccount(null, env20525[0]);
|
|
if (account == null) {
|
|
const handleConnectionsUpdate = function handleConnectionsUpdate(a0) {
|
|
if (env20525[2] != null) {
|
|
let accounts = a0.accounts;
|
|
if (accounts == null) {
|
|
accounts = [];
|
|
}
|
|
const r4 = accounts.find((account) => account.type === env20525[2].type);
|
|
if (r4 != null) {
|
|
(0, env31690[0])({
|
|
access_token: r4.access_token
|
|
});
|
|
Dispatcher.unsubscribe("USER_CONNECTIONS_UPDATE", env31690[3]);
|
|
ComponentDispatch.unsubscribe(ComponentActions.CONNECTIONS_CALLBACK_ERROR, env31690[4]);
|
|
}
|
|
}
|
|
};
|
|
env31690[3] = handleConnectionsUpdate;
|
|
const handleConnectionsCallbackError = function handleConnectionsCallbackError() {
|
|
env31690[1](new RPCError({
|
|
errorCode: RPCErrors.OAUTH2_ERROR
|
|
}, `OAuth2 setup for "${env20525[0]}" failed`));
|
|
Dispatcher.unsubscribe("USER_CONNECTIONS_UPDATE", env31690[3]);
|
|
ComponentDispatch.unsubscribe(ComponentActions.CONNECTIONS_CALLBACK_ERROR, env31690[4]);
|
|
};
|
|
env31690[4] = handleConnectionsCallbackError;
|
|
Dispatcher.subscribe("USER_CONNECTIONS_UPDATE", handleConnectionsUpdate);
|
|
ComponentDispatch.subscribe(ComponentActions.CONNECTIONS_CALLBACK_ERROR, handleConnectionsCallbackError);
|
|
authorizeConnection_native({
|
|
platformType: env20525[2].type,
|
|
location: AnalyticsLocations.ACTIVITY_RPC,
|
|
successRedirect: env20525[1]
|
|
});
|
|
break L16;
|
|
}
|
|
c30639_5 = 1;
|
|
const r26 = await ConnectedAccountsActionCreators.refreshAccessToken(env20525[2].type, account.id);
|
|
const r89 = "Refreshing access token did not return a new access token";
|
|
env31690[2] = r26;
|
|
if (env31690[2] == null) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.OAUTH2_ERROR
|
|
}, r89);
|
|
}
|
|
(0, env31690[0])({
|
|
access_token: env31690[2]
|
|
});
|
|
c30639_5 = 0;
|
|
} catch ($e) {
|
|
const r30 = $e;
|
|
let r7 = r30;
|
|
c30639_4 = r30;
|
|
if (c30639_5 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r119 = c30639_4;
|
|
c30639_5 = 0;
|
|
(0, env31690[1])(r119);
|
|
break L14;
|
|
} catch (r116) {
|
|
r7 = r116;
|
|
c30639_4 = r116;
|
|
if (c30639_5 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
return new r43(function() {
|
|
return c20526_0.apply(this, arguments);
|
|
});
|
|
}
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.UNAUTHORIZED_FOR_APPLICATION
|
|
}, "Command not available for this application");
|
|
}
|
|
};
|
|
const MAYBE_GET_PROVIDER_ACCESS_TOKEN = RPCCommands.MAYBE_GET_PROVIDER_ACCESS_TOKEN;
|
|
const scope2 = {};
|
|
scope2[RPC_SCOPE_CONFIG.ANY] = [RPC_AUTHENTICATED_SCOPE];
|
|
c9406_3 = async (c20527_0) => {
|
|
let c27502_0 = c20527_0.socket;
|
|
let c27502_1 = c20527_0.args.provider;
|
|
await void 0;
|
|
validatePostMessageTransport(c27502_0.transport);
|
|
let c27502_2 = validateApplication(c27502_0.application);
|
|
let c27502_3 = Platforms.get(c27502_1);
|
|
if (c27502_3 == null) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.INVALID_PROVIDER
|
|
}, `Platform not found for provider "${c27502_1}"`);
|
|
}
|
|
if (c27502_1 !== PlatformTypes.AMAZON_MUSIC) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.UNAUTHORIZED_FOR_APPLICATION
|
|
}, "Command not available for this application");
|
|
}
|
|
if (!c9406_10.has(c27502_2)) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.UNAUTHORIZED_FOR_APPLICATION
|
|
}, "Command not available for this application");
|
|
}
|
|
let c27502_4 = ConnectedAccountsStore.getAccount(null, c27502_1);
|
|
if (c27502_4 == null) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.NO_CONNECTION_FOUND
|
|
}, "No connection found");
|
|
}
|
|
let c27502_5 = await ConnectedAccountsActionCreators.refreshAccessToken(c27502_3.type, c27502_4.id);
|
|
if (c27502_5 == null) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.OAUTH2_ERROR
|
|
}, "Refreshing access token did not return a new access token");
|
|
}
|
|
return {
|
|
access_token: c27502_5
|
|
};
|
|
};
|
|
r44[MAYBE_GET_PROVIDER_ACCESS_TOKEN] = {
|
|
scope: scope2,
|
|
validation: (a0) => createRpcJoiSchemaObject(a0).required().keys({
|
|
provider: a0.string().required()
|
|
}),
|
|
handler: function() {
|
|
return c9406_3.apply(this, arguments);
|
|
}
|
|
};
|
|
export default r44;
|