diff --git a/types/accedo__accedo-one/accedo__accedo-one-tests.ts b/types/accedo__accedo-one/accedo__accedo-one-tests.ts new file mode 100644 index 0000000000..aaa9ce03e0 --- /dev/null +++ b/types/accedo__accedo-one/accedo__accedo-one-tests.ts @@ -0,0 +1,41 @@ +import accedoOne = require("@accedo/accedo-one"); + +accedoOne(); // $ExpectError + +accedoOne({ + appKey: 0, // $ExpectError +}); + +const accedo = accedoOne({ + appKey: 'asf8ggtg0a63189cvbs1278jj354', +}); + +accedo.getEntries(''); // $ExpectError +accedo.getEntries(0); // $ExpectError + +accedo.getEntryById(); // $ExpectError +accedo.getEntryByAlias(); // $ExpectError +accedo.sendLog(); // $ExpectError +accedo.getMetadataByKey(); // $ExpectError +accedo.getAllApplicationScopeDataByUser(); // $ExpectError +accedo.getAllApplicationGroupScopeDataByUser(); // $ExpectError +accedo.getApplicationScopeDataByUserAndKey(); // $ExpectError +accedo.getApplicationScopeDataByUserAndKey('userName01'); // $ExpectError + +accedo.getApplicationGroupScopeDataByUserAndKey(); // $ExpectError +accedo.getApplicationGroupScopeDataByUserAndKey('userName01'); // $ExpectError + +accedo.setApplicationScopeUserData(); // $ExpectError +accedo.setApplicationScopeUserData('userName01'); // $ExpectError + +accedo.setApplicationGroupScopeUserData(); // $ExpectError +accedo.setApplicationGroupScopeUserData('userName01'); // $ExpectError + +accedo.setApplicationScopeUserDataByKey(); // $ExpectError +accedo.setApplicationScopeUserDataByKey('userName01'); // $ExpectError + +accedo.setApplicationGroupScopeUserDataByKey(); // $ExpectError +accedo.setApplicationGroupScopeUserDataByKey('userName01'); // $ExpectError +accedo.setApplicationGroupScopeUserDataByKey('userName01', 'key02'); // $ExpectError + +accedo.sendLogs(); // $ExpectError diff --git a/types/accedo__accedo-one/index.d.ts b/types/accedo__accedo-one/index.d.ts new file mode 100644 index 0000000000..70461ecd28 --- /dev/null +++ b/types/accedo__accedo-one/index.d.ts @@ -0,0 +1,407 @@ +// Type definitions for @accedo/accedo-one 4.0 +// Project: https://www.accedo.tv/one +// Definitions by: Alexander P. Cerutti +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Minimum TypeScript Version: 3.1 + +/** + * @example + * ~ import accedoOne from "@accedo/accedo-one"; // ESM Syntax + * ~ import accedoOne = require("@accedo/accedo-one"); // CJS Syntax + * ~ const accedo = accedoOne({ ... }); + * ~ + * ~ accedo.getEntries(...); + * + * @param config + */ + +export as namespace accedoOne; +declare function accedoOne(config: AccedoConfig): AccedoClient; +export = accedoOne; +export {}; + +declare class AccedoClient { + config: AccedoConfig; + + /** + * Get all the content entries, based on the given parameters. + * DO NOT use several of the id, alias, typeId and typeAlias + * options at the same time - behaviour would be ungaranteed. + * + * @param params + */ + + getEntries(params?: AccedoEntryParams): Promise; + + /** + * Get one content entry by id, based on the given parameters. + * + * @param id + * @param params + */ + + getEntryById(id: string, params?: Pick): Promise; + + /** + * Get one content entry, based on the given parameters. + * + * @param alias + * @param params + */ + + getEntryByAlias(alias: A, params?: Pick): Promise; + + /** + * Create a session and store it for reuse in this client instance. + * Note you do not usually need to worry about this. Other methods + * will call it automatically for you when it is needed. + * + * @returns a Promise of a string, the sessionKey + */ + + createSession(): Promise; + + /** + * Get the current log level + * + * @returns a promise of the log level (string) + */ + + getLogLevel(): Promise; + + /** + * NOTE: the behaviour varies when run on Node.js or on browsers. + * + * On Node.js, the log will be sent immediately. + * On browsers: add the log to a queue so several logs may be sent + * as a batch, when a predefined total size is reached or after a + * debouncing delay. Whenever the user navigates away, the SDK will + * also attempt to send any queued-up log. + * + * If the current log level is high enough, lower level logs will be ignored. + * + * @param level the log level + * @param details the log information + * @param metadata extra metadata (will go through JSON.stringify). Can be passed as any number of trailing arguments. + */ + + sendLog(level: AccedoLog.Level, details: Readonly, metadata?: any): Promise; + + /** + * Returns the currently stored sessionKey for this client instance + * + * @returns string: the sessionKey, if any + */ + + getSessionKey(): string; + + /** + * Get the current application status + * + * @returns A promise of the application status (string) + */ + + getApplicationStatus(): Promise; + + /** + * Lists all the assets. + * + * @returns A promise of a hash of assets (key: asset name, value: asset URL) + */ + + getAllAssets(): Promise; + + /** + * Send a usage START event + * + * @returns A promise denoting the success of the operation + */ + + sendUsageStartEvent(): Promise; + + /** + * Send a usage QUIT event + * + * @param retentionTimeInSeconds the retention time, in seconds + * @returns A promise denoting the success of the operation + */ + + sendUsageStopEvent(retentionTimeInSeconds?: number | string): Promise; + + /** + * Get all the enabled plugins + * + * @returns A promise of the requested data + */ + + getAllEnabledPlugins(): Promise; + + /** + * Get the profile information + * + * @returns A promise of the requested data + */ + + getProfileInfo(): Promise; + + /** + * Get all the metadata + * + * @returns A promise of the requested data + */ + + getAllMetadata(): Promise; + + /** + * Get the metadata by a specific key + * + * @param key a key to get specific metadata + * @returns a promise of the requested data + */ + + getMetadataByKey(key: string): Promise; + + /** + * Get the metadata by specific keys + * + * @param keys an array of keys (strings) + * @returns a promise of the requested data + */ + + getMetadataByKeys(keys: string[]): Promise; + + /** + * Get all the application-scope data for a given user + * + * @param userName an Accedo One user + * @returns A promise of the requested data + */ + + getAllApplicationScopeDataByUser(userName: string): Promise; + + /** + * Get all the application-group-scope data for a given user + * + * @param userName an Accedo One user + * @returns A promise of the requested data + */ + + getAllApplicationGroupScopeDataByUser(userName: string): Promise; + + /** + * Get all the application-scope data for a given user and data key + * + * @param userName an Accedo One user + * @param key a key to specify what data to obtain + */ + + getApplicationScopeDataByUserAndKey(userName: string, key: string): Promise; + + /** + * Get all the application-group-scope data for a given user + * + * @param userName an Accedo One user + * @param key a key to specify what data to obtain + * @returns A promise of the requested data + */ + + getApplicationGroupScopeDataByUserAndKey(userName: string, key: string): Promise; + + /** + * Set the application-scope data for a given user + * + * @param userName an Accedo One user + * @param data the data to store + * @returns A promise of the requested data + */ + + setApplicationScopeUserData(userName: string, data: D): Promise; + + /** + * Set the application-group-scope data for a given user + * + * @param userName an Accedo One user + * @param data the data to store + * @returns A promise of the requested data + */ + + setApplicationGroupScopeUserData(userName: string, data: D): Promise; + + /** + * Set the application-scope data for a given user + * + * @param userName an Accedo One user + * @param key a key to specify what data to obtain + * @param data the data to store + * @returns A promise of the requested data + */ + + setApplicationScopeUserDataByKey(userName: string, key: string, data: D): Promise; + + /** + * Set the application-group-scope data for a given user + * + * @param userName an Accedo One user + * @param key a key to specify what data to obtain + * @param data the data to store + * @returns A promise of the requested data + */ + + setApplicationGroupScopeUserDataByKey(userName: string, key: string, data: D): Promise; + + /** + * Get all the available locales + * + * @returns A promise of the requested data + */ + + getAvailableLocales(): Promise<{ locales: AccedoLocale[] }>; + + /** + * Send batched logs, each with its own level, timestamp, details and extra metadata. + * Note that on browsers, the other method, sendLog, is more convenient as it will + * auto-batch logs for you. + * + * @param logs + * @returns A promise of the success of the operation + */ + + sendLogs(logs: ReadonlyArray): Promise; +} + +declare namespace AccedoLog { + enum Level { + DEBUG = 'debug', + INFO = 'info', + WARN = 'warn', + ERROR = 'error', + } + + interface Details { + /** The log message */ + message: string; + + /** The error code (max 5 digits) */ + errorCode?: number; + + /** The dimension 1 information */ + dim1?: string; + + /** The dimension 2 information */ + dim2?: string; + + /** The dimension 3 information */ + dim3?: string; + + /** The dimension 4 information */ + dim4?: string; + } + + interface Logobject extends Details { + /** + * the log type + */ + + logType: Level; + + /** + * The timestamp for the log, as a UTC ISO 8601 string + * (ie. '2016-07-04T06:17:21Z'), or a POSIX millisecond + * number + */ + + timestamp: string | number; + + /** Extra metadata (will go through JSON.stringify) */ + metadata?: any; + } +} + +interface AccedoEntryParams { + /** when true, get the preview version */ + preview?: boolean; + + /** when given, get the version at the given time */ + at?: string | Date; + + /** an array of entry ids (strings) */ + id?: string[]; + + /** an array of entry aliases (strings) */ + alias?: string[]; + + /** only return entries of the given type ids (strings) */ + typeId?: string[]; + + /** only return entries whose entry type has this alias */ + typeAlias?: string; + + /** + * Limit to that many results per page (limits as per Accedo + * One API, currently 1 to 50, default 20) + */ + size?: number | string; + + /** Offset the result by that many pages */ + offset?: number | string; + + /** + * if available, get the version for the given locale + * (defaults to the default locale) + */ + + locale?: string; +} + +interface AccedoProfile { + profileId: string; + profileName: string; + profileDescription: string; + profileLastModified: string; +} + +interface AccedoConfig { + /** + * A function that should return an object with deviceId and + * sessionKey properties, saved from previous sessions (see + * onDeviceIdGenerated, onSessionKeyChanged) + */ + + browserInfoProvider?: () => { + deviceId: string; + sessionKey: string; + }; + + /** The application Key */ + appKey: string; + + /** The device identifier (if not provided, a uuid will be generated instead) */ + deviceId?: string; + + /** The sessionKey (note a new one may be created when not given or expired) */ + sessionKey?: string; + + /** the user's IP, given to Accedo One for every request this client will trigger (for geolocation). */ + ip?: string; + + /** A function to use to see this SDK's logs */ + log?: (...args: any[]) => void; + + /** Callback to obtain the new deviceId, if one gets generated */ + onDeviceIdGenerated?: (deviceId: string) => void; + + /** Callback to obtain the sessionKey, anytime a new one gets generated */ + onSessionKeyChanged?: (sessionKey: string) => void; + + /** All APIs calls will use this as the base API URL (defaults to the Accedo One API URL) */ + target?: string; +} + +interface AccedoLocale { + code: string; + displayName: string; + countryInfo: { + alpha2Code: string; + alpha3Code: string; + }; +} diff --git a/types/accedo__accedo-one/tsconfig.json b/types/accedo__accedo-one/tsconfig.json new file mode 100644 index 0000000000..cf9f87e2a9 --- /dev/null +++ b/types/accedo__accedo-one/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "paths": { + "@accedo/accedo-one": [ + "accedo__accedo-one" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "accedo__accedo-one-tests.ts" + ] +} diff --git a/types/accedo__accedo-one/tslint.json b/types/accedo__accedo-one/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/accedo__accedo-one/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }