@gigya-ts/web-sdk
Type definitions for interacting with the Gigya / SAP Customer Data Cloud Web SDK.
See @gigya-ts/gigya if you are working with the REST API instead.
Installation
npm install @gigya-ts/web-sdk
Usage
Define your own schema types. They will be used to type the data used when interacting with the Web SDK.
import { GigyaPreference } from '@gigya-ts/web-sdk';
type MyDataSchema = {
myCustomString: string;
myCustomObject: {
myCustomNumber: number;
};
};
type MyPreferencesSchema = {
terms: {
myTerms: GigyaPreference;
};
myCustomPreference: GigyaPreference;
};
type MySubscriptionsSchema = {};
Then, extend the global window with your the Gigya Web SDK, including your schemas:
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);
},
});
};