Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Dynamic Imports of SDK Modules" #263

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"build-dev": "webpack --config webpack.dev.js",
"test": "jest --config test/jest.config.js",
"testCoverage": "NODE_ENV=test jest --config test/jest.config.js",
"postinstall": "npm update @firebolt-js/manage-sdk",
"format": "prettier --write \"**/*.js\"",
"lint": "eslint ."
},
Expand Down
96 changes: 69 additions & 27 deletions src/FireboltExampleInvoker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,34 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as CoreSDK from '@firebolt-js/sdk';
import * as ManageSDK from '@firebolt-js/manage-sdk';
import FireboltSdkManager from './utils/FireboltSdkManager';
import { Accessibility, Account, Advertising, Authentication, Capabilities, Device, Discovery, Keyboard, Lifecycle, Localization, Metrics, Profile, Parameters, SecondScreen, SecureStorage } from '@firebolt-js/sdk';
import {
Advertising as ManageAdvertising,
AcknowledgeChallenge,
Device as ManageDevice,
Wifi,
Account as ManageAccount,
ClosedCaptions,
Keyboard as ManageKeyboard,
Localization as ManageLocalization,
PinChallenge,
Privacy,
VoiceGuidance,
UserGrants,
Metrics as ManageMetrics,
SecureStorage as ManageSecureStorage,
Discovery as ManageDiscovery,
AudioDescriptions,
HDMIInput,
} from '@firebolt-js/manage-sdk';
import { Content } from '@firebolt-js/discovery-sdk';
import DiscoveryInvoker from './invokers/DiscoveryInvoker';
const discoveryInvoker = new DiscoveryInvoker();
const logger = require('./utils/Logger')('FireboltExampleInvoker.js');
import { removeSetInMethodName } from './utils/Utils';
import { eventEmitter } from './Toast';
import { CONSTANTS } from './constant';

/**
* Dynamically check if the Discovery SDK is available as a dependency.
* If available, require it. Otherwise, log a warning.
*/
const dependencies = DEPENDENCIES; // Injected by Webpack DefinePlugin
let DiscoverySDK;

if (dependencies.hasOwnProperty('@firebolt-js/discovery-sdk')) {
try {
DiscoverySDK = require('@firebolt-js/discovery-sdk');
} catch (error) {
console.warn('DiscoverySDK is not available:', error);
}
}

// Initialize the Firebolt SDK Module Loader
const sdkManager = new FireboltSdkManager(CoreSDK, ManageSDK, DiscoverySDK, dependencies);

// Dynamically generate the module map based on the imported SDKs
const moduleMap = sdkManager.generateModuleMap();

// Export the dynamically created module map
export const MODULE_MAP = moduleMap;

// Commenting the below APIs as they have been deprecated from discovery sdk , can be uncommented when added as ripple-rpc APIs in future ticket
const MAP = {
'discovery.purchasedContent': discoveryInvoker.purchasedContent.bind(discoveryInvoker),
Expand All @@ -58,6 +52,54 @@ const MAP = {
// 'content.entity': discoveryInvoker.getEntityInfo.bind(discoveryInvoker),
};

const CORE_MODULE_MAP = {
accessibility: Accessibility,
account: Account,
advertising: Advertising,
authentication: Authentication,
capabilities: Capabilities,
device: Device,
discovery: Discovery,
keyboard: Keyboard,
lifecycle: Lifecycle,
localization: Localization,
metrics: Metrics,
profile: Profile,
parameters: Parameters,
secondscreen: SecondScreen,
securestorage: SecureStorage,
};

const MANAGE_MODULE_MAP = {
advertising: ManageAdvertising,
acknowledgechallenge: AcknowledgeChallenge,
device: ManageDevice,
wifi: Wifi,
account: ManageAccount,
closedcaptions: ClosedCaptions,
keyboard: ManageKeyboard,
pinchallenge: PinChallenge,
privacy: Privacy,
voiceguidance: VoiceGuidance,
localization: ManageLocalization,
usergrants: UserGrants,
metrics: ManageMetrics,
securestorage: ManageSecureStorage,
discovery: ManageDiscovery,
audiodescriptions: AudioDescriptions,
hdmiinput: HDMIInput,
};

const DISCOVERY_MODULE_MAP = {
content: Content,
};

export const MODULE_MAP = {
core: CORE_MODULE_MAP,
manage: MANAGE_MODULE_MAP,
discovery: DISCOVERY_MODULE_MAP,
};

// importing additional invoker which has external sdk's being exported and adding those modules in the MODULE_MAP
try {
const additionalInvoker = require('../plugins/FireboltExtensionInvoker').default;
Expand Down
1 change: 0 additions & 1 deletion src/FireboltTransportInvoker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import Transport from '@firebolt-js/sdk/dist/lib/Transport';
import { CONSTANTS } from './constant';
const logger = require('./utils/Logger')('FireboltTransportInvoker.js');

let invokeManager, invokeProvider;
try {
Expand Down
57 changes: 30 additions & 27 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,9 @@
*/

import CONFIG_CONSTANTS from 'config';
import * as CoreSDK from '@firebolt-js/sdk';
import * as ManageSDK from '@firebolt-js/manage-sdk';
import FireboltSdkManager from './utils/FireboltSdkManager';

/**
* Dynamically check if the Discovery SDK is available as a dependency.
* If available, require it. Otherwise, log a warning.
*/
const dependencies = DEPENDENCIES; // Injected by Webpack DefinePlugin
let DiscoverySDK;

if (dependencies.hasOwnProperty('@firebolt-js/discovery-sdk')) {
try {
DiscoverySDK = require('@firebolt-js/discovery-sdk');
} catch (error) {
console.warn('DiscoverySDK is not available:', error);
}
}

// Initialize the Firebolt SDK Module Loader
const sdkManager = new FireboltSdkManager(CoreSDK, ManageSDK, DiscoverySDK, dependencies);

const defaultSdks = sdkManager.generateDefaultSdkConstants();

import CORE_OPEN_RPC from '@firebolt-js/sdk/dist/firebolt-core-open-rpc';
import MANAGE_OPEN_RPC from '@firebolt-js/manage-sdk/dist/firebolt-manage-open-rpc';
import DISCOVERY_OPEN_RPC from '@firebolt-js/discovery-sdk/dist/firebolt-discovery-open-rpc';
export const CONSTANTS = {
ALL_SDKS: 'ALL SDKS',
SDK: 'SDK',
Expand Down Expand Up @@ -163,13 +142,37 @@ export const CONSTANTS = {
EXCLUDED_METHODS_FOR_SDK: [],
EXCLUDED_METHODS_FOR_TRANSPORT: [],
REGISTERPROVIDER: 'registerprovider',
defaultSDKs: defaultSdks,
INVOKEPROVIDER: 'invokeProvider',
INVOKEMANAGER: 'invokeManager',
defaultSDKs: [
{
name: 'Core',
openRpc: CORE_OPEN_RPC,
validation: function () {
return !(process.env.MF_VALUE && !process.env.MOCKOS);
},
unavailableMessage: 'MockOs is not running',
},
{
name: 'Manage',
openRpc: MANAGE_OPEN_RPC,
validation: function () {
return !(process.env.MF_VALUE && !process.env.MOCKOS);
},
unavailableMessage: 'MockOs is not running',
},
{
name: 'Discovery',
openRpc: DISCOVERY_OPEN_RPC,
validation: function () {
return !(process.env.MF_VALUE && !process.env.MOCKOS);
},
unavailableMessage: 'MockOs is not running',
},
],

additionalSDKs: [],
EXCLUDED_METHODS_FOR_MFOS: [],
PASCAL_CASED_MODULES: ['SecondScreen', 'SecureStorage', 'ClosedCaptions', 'AcknowledgeChallenge', 'DeveloperTools', 'LifecycleManagement', 'PinChallenge', 'UserGrants', 'VoiceGuidance'],
X_MODULE_DESCRIPTIONS: 'x-module-descriptions',
...CONFIG_CONSTANTS,
VERSIONS: 'Versions',
NO_RESULT_OR_ERROR_MESSAGE: 'No result or error in response. eg: {jsonrpc: "2.0", id: x }',
Expand Down
Loading
Loading