diff --git a/package.json b/package.json index 6241d9b..c0c1f35 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "react-native-autolocalise", - "version": "0.2.0", + "version": "0.2.1", "description": "Auto-translation SDK for React Native and Expo applications", "main": "dist/index.js", "module": "dist/index.esm.js", @@ -24,9 +24,9 @@ "author": "AutoLocalise", "license": "MIT", "peerDependencies": { - "react": ">=18.0.0", - "react-native": ">=0.73.0", - "@react-native-async-storage/async-storage": ">=1.18.0" + "react": ">=16.8.0", + "react-native": ">=0.60.0", + "@react-native-async-storage/async-storage": ">=1.0.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.0", diff --git a/src/services/translation.ts b/src/services/translation.ts index 67c1365..9b2e32f 100644 --- a/src/services/translation.ts +++ b/src/services/translation.ts @@ -6,6 +6,7 @@ import { TranslationResponse, } from "../types"; import { getStorageAdapter } from "../storage"; +import { VERSION } from "../version"; export class TranslationService { private config: TranslationConfig; @@ -87,12 +88,13 @@ export class TranslationService { this.pendingTranslations.clear(); if (allTexts.length > 0) { - // Modify API request to include context + // Modify API request to include context and version const request: TranslationRequest = { texts: allTexts, sourceLocale: this.config.sourceLocale, targetLocale: this.config.targetLocale, apiKey: this.config.apiKey, + version: `react-native-v${VERSION}`, }; try { diff --git a/src/storage/index.ts b/src/storage/index.ts index 6237a6a..1b53fac 100644 --- a/src/storage/index.ts +++ b/src/storage/index.ts @@ -1,10 +1,4 @@ -// import AsyncStorage from "@react-native-async-storage/async-storage"; - -interface StorageAdapter { - getItem: (key: string) => Promise; - setItem: (key: string, value: string) => Promise; - removeItem: (key: string) => Promise; -} +import { StorageAdapter } from "../types"; export async function getStorageAdapter(): Promise { try { @@ -14,6 +8,11 @@ export async function getStorageAdapter(): Promise { if (AsyncStorage?.default) { return AsyncStorage.default; } + + // If AsyncStorage is not available, throw an error + throw new Error( + "No storage adapter available. Please install @react-native-async-storage/async-storage" + ); } catch (e) { throw new Error( "No storage adapter available. Please install @react-native-async-storage/async-storage" diff --git a/src/types.ts b/src/types.ts index a914225..844ec78 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,6 +21,7 @@ export interface TranslationRequest { sourceLocale: string; targetLocale: string; apiKey: string; + version: string; } export interface TranslationResponse { diff --git a/src/types/async-storage.d.ts b/src/types/async-storage.d.ts new file mode 100644 index 0000000..983f506 --- /dev/null +++ b/src/types/async-storage.d.ts @@ -0,0 +1,10 @@ +declare module "@react-native-async-storage/async-storage" { + interface AsyncStorageStatic { + getItem(key: string): Promise; + setItem(key: string, value: string): Promise; + removeItem(key: string): Promise; + } + + const AsyncStorage: AsyncStorageStatic; + export default AsyncStorage; +} diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..74857b6 --- /dev/null +++ b/src/version.ts @@ -0,0 +1,3 @@ +// This file is auto-generated during build +// Update this manually or via build script +export const VERSION = "0.2.1";