diff --git a/src/lib/alarms/csfloat_trade_pings.ts b/src/lib/alarms/csfloat_trade_pings.ts index f39993f1..30a64915 100644 --- a/src/lib/alarms/csfloat_trade_pings.ts +++ b/src/lib/alarms/csfloat_trade_pings.ts @@ -3,6 +3,7 @@ import {FetchPendingTrades} from '../bridge/handlers/fetch_pending_trades'; import {pingTradeHistory} from './trade_history'; import {pingSentTradeOffers} from './trade_offer'; import {HasPermissions} from '../bridge/handlers/has_permissions'; +import {PingExtensionStatus} from '../bridge/handlers/ping_extension_status'; export const PING_CSFLOAT_TRADE_STATUS_ALARM_NAME = 'ping_csfloat_trade_status_alarm'; @@ -19,6 +20,13 @@ export async function pingTradeStatus() { return; } + // Ping status of ext + permissions + try { + await PingExtensionStatus.handleRequest({}, {}); + } catch (e) { + console.error('failed to ping extension status to csfloat', e); + } + let pendingTrades: Trade[]; try { const resp = await FetchPendingTrades.handleRequest({limit: 500}, {}); diff --git a/src/lib/bridge/handlers/handlers.ts b/src/lib/bridge/handlers/handlers.ts index 65bccd24..2416a508 100644 --- a/src/lib/bridge/handlers/handlers.ts +++ b/src/lib/bridge/handlers/handlers.ts @@ -16,6 +16,7 @@ import {TradeHistoryStatus} from './trade_history_status'; import {TradeOfferStatus} from './trade_offer_status'; import {HasPermissions} from './has_permissions'; import {PingSetupExtension} from './ping_setup_extension'; +import {PingExtensionStatus} from './ping_extension_status'; export const HANDLERS_MAP: {[key in RequestType]: RequestHandler} = { [RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage, @@ -34,4 +35,5 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler} = { [RequestType.TRADE_OFFER_STATUS]: TradeOfferStatus, [RequestType.HAS_PERMISSIONS]: HasPermissions, [RequestType.PING_SETUP_EXTENSION]: PingSetupExtension, + [RequestType.PING_EXTENSION_STATUS]: PingExtensionStatus, }; diff --git a/src/lib/bridge/handlers/ping_extension_status.ts b/src/lib/bridge/handlers/ping_extension_status.ts new file mode 100644 index 00000000..ae6e4fcf --- /dev/null +++ b/src/lib/bridge/handlers/ping_extension_status.ts @@ -0,0 +1,51 @@ +import {SimpleHandler} from './main'; +import {RequestType} from './types'; +import {environment} from '../../../environment'; +import {HasPermissions} from './has_permissions'; +import {ExtensionVersion} from './extension_version'; + +export interface PingExtensionStatusRequest {} + +export interface PingExtensionStatusResponse {} + +export const PingExtensionStatus = new SimpleHandler( + RequestType.PING_EXTENSION_STATUS, + async (req) => { + const steamPoweredPermissions = await HasPermissions.handleRequest( + { + permissions: [], + origins: ['*://*.steampowered.com/*'], + }, + {} + ); + + const steamCommunityPermissions = await HasPermissions.handleRequest( + { + permissions: [], + origins: ['*://*.steamcommunity.com/*'], + }, + {} + ); + + const versionResp = await ExtensionVersion.handleRequest({}, {}); + + const resp = await fetch(`${environment.csfloat_base_api_url}/v1/me/extension/status`, { + credentials: 'include', + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + steam_community_permission: steamCommunityPermissions.granted, + steam_powered_permission: steamPoweredPermissions.granted, + version: versionResp.version, + }), + }); + + if (resp.status !== 200) { + throw new Error('invalid status'); + } + + return resp.json() as Promise; + } +); diff --git a/src/lib/bridge/handlers/types.ts b/src/lib/bridge/handlers/types.ts index 61ea91bd..eaef6d6c 100644 --- a/src/lib/bridge/handlers/types.ts +++ b/src/lib/bridge/handlers/types.ts @@ -15,4 +15,5 @@ export enum RequestType { TRADE_OFFER_STATUS, HAS_PERMISSIONS, PING_SETUP_EXTENSION, + PING_EXTENSION_STATUS, } diff --git a/src/lib/page_scripts/trade_offers.ts b/src/lib/page_scripts/trade_offers.ts index 2a9f1153..c9be74c0 100644 --- a/src/lib/page_scripts/trade_offers.ts +++ b/src/lib/page_scripts/trade_offers.ts @@ -3,6 +3,7 @@ import '../components/trade_offers/better_tracking'; import {inPageContext} from '../utils/snips'; import {ClientSend} from '../bridge/client'; import {PingSetupExtension} from '../bridge/handlers/ping_setup_extension'; +import {PingExtensionStatus} from '../bridge/handlers/ping_extension_status'; init('src/lib/page_scripts/trade_offers.js', main); @@ -31,6 +32,7 @@ if (!inPageContext()) { if (granted) { widget[0].parentElement?.removeChild(widget[0]); ClientSend(PingSetupExtension, {}); + ClientSend(PingExtensionStatus, {}); } else { alert('Failed to obtain permissions'); }