@gigya-ts/web-sdk
v0.1.13
Published
TypeScript definitions for the Gigya Web SDK
Downloads
818
Readme
@gigya-ts/web-sdk
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!).
Installation
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
Usage
0. (Optional) Define your custom Gigya schemas
See adding custom schemas to define your custom schemas (data, preferences, etc.) so that response types from the Web SDK include your custom fields.
1. Extend the global window with the gigya
types
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);
},
});
};