Add type-safety to a Gigya Web SDK project.
See @gigya-ts/gigya if you are using the Gigya REST API instead (even from the browser!).
Install the @gigya-ts/gigya package from your package manager of choice:
# npm
npm add @gigya-ts/web-sdk
# pnpm
pnpm add @gigya-ts/web-sdk
See adding custom schemas to define your custom schemas (data, preferences, etc.) so that response types from the Web SDK include your custom fields.
Extend the global window with the Gigya Web SDK, including your schemas:
// my-gigya.ts
import { GigyaWebSDK } from '@gigya-ts/web-sdk';
declare global {
interface Window {
onGigyaServiceReady?: () => void;
gigya?: GigyaWebSDK<MyAccountSchema, MyPreferencesSchema, MySubscriptionsSchema>;
}
}
Once the global window has been extended, you can use the Web SDK as you normally would:
window.onGigyaServiceReady = () => {
window.gigya?.accounts.getAccountInfo({
callback: (response) => {
console.log('gigya.account.getAccountInfo response', response);
},
});
};