@shobdo/js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +41 -0
- package/dist/errors.d.ts +14 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.ts +49 -0
- package/package.json +42 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApiResponse, FullEntry, SearchOptions, SearchResult } from "./types";
|
|
2
|
+
export interface ClientConfig {
|
|
3
|
+
/** The Shobdo API key */
|
|
4
|
+
apiKey: string;
|
|
5
|
+
/** Optional base URL (defaults to https://shobdo.me/api/v1) */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/** Optional custom fetch implementation */
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
export declare class ShobdoClient {
|
|
11
|
+
private apiKey;
|
|
12
|
+
private baseUrl;
|
|
13
|
+
private fetchImpl;
|
|
14
|
+
constructor(config: ClientConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Search across all available dictionaries
|
|
17
|
+
* @param query The search term
|
|
18
|
+
* @param options Search filters and pagination
|
|
19
|
+
*/
|
|
20
|
+
search(query: string, options?: SearchOptions): Promise<ApiResponse<SearchResult[]>>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve a full dictionary entry by its unique ID
|
|
23
|
+
* @param source The dictionary ID
|
|
24
|
+
* @param id The entry ID
|
|
25
|
+
*/
|
|
26
|
+
getEntryById(source: string, id: string): Promise<ApiResponse<FullEntry>>;
|
|
27
|
+
/**
|
|
28
|
+
* Look up a dictionary entry by word string
|
|
29
|
+
* @param source The dictionary ID
|
|
30
|
+
* @param word The word to look up
|
|
31
|
+
*/
|
|
32
|
+
getEntryByWord(source: string, word: string): Promise<ApiResponse<FullEntry>>;
|
|
33
|
+
/**
|
|
34
|
+
* Get the direct URL to the pronunciation audio for an entry
|
|
35
|
+
* @param source The dictionary ID
|
|
36
|
+
* @param lexid The entry ID
|
|
37
|
+
* @returns The full URL to the audio endpoint (which redirects to the CDN)
|
|
38
|
+
*/
|
|
39
|
+
getAudioUrl(source: string, lexid: string): string;
|
|
40
|
+
private request;
|
|
41
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class ShobdoError extends Error {
|
|
2
|
+
status: number;
|
|
3
|
+
details?: any;
|
|
4
|
+
constructor(message: string, status: number, details?: any);
|
|
5
|
+
}
|
|
6
|
+
export declare class AuthenticationError extends ShobdoError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class RateLimitError extends ShobdoError {
|
|
10
|
+
constructor(message?: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class NotFoundError extends ShobdoError {
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var y=(s,e)=>{for(var t in e)u(s,t,{get:e[t],enumerable:!0})},g=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!m.call(s,n)&&n!==t&&u(s,n,{get:()=>e[n],enumerable:!(r=f(e,n))||r.enumerable});return s};var R=s=>g(u({},"__esModule",{value:!0}),s);var w={};y(w,{AuthenticationError:()=>i,NotFoundError:()=>c,RateLimitError:()=>a,ShobdoClient:()=>h,ShobdoError:()=>o});module.exports=R(w);var o=class extends Error{status;details;constructor(e,t,r){super(e),this.name="ShobdoError",this.status=t,this.details=r}},i=class extends o{constructor(e="Authentication failed. Check your API key."){super(e,401),this.name="AuthenticationError"}},a=class extends o{constructor(e="Rate limit exceeded. Please upgrade your plan."){super(e,429),this.name="RateLimitError"}},c=class extends o{constructor(e="Resource not found."){super(e,404),this.name="NotFoundError"}};var h=class{apiKey;baseUrl;fetchImpl;constructor(e){if(!e.apiKey)throw new Error("Shobdo API key is required");if(this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||"https://shobdo.me/api/v1",e.fetch)this.fetchImpl=e.fetch;else if(typeof fetch<"u")this.fetchImpl=fetch;else throw new Error("No global fetch API found. Please provide a custom fetch implementation in ClientConfig.")}async search(e,t){let r=new URLSearchParams({q:e});return t&&(t.limit!==void 0&&r.append("limit",t.limit.toString()),t.offset!==void 0&&r.append("offset",t.offset.toString()),t.lang&&r.append("lang",t.lang),t.source&&r.append("source",t.source),t.matchType&&r.append("matchType",t.matchType)),this.request(`/search?${r.toString()}`)}async getEntryById(e,t){return this.request(`/entry/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async getEntryByWord(e,t){return this.request(`/entry/${encodeURIComponent(e)}/word/${encodeURIComponent(t)}`)}getAudioUrl(e,t){return`${this.baseUrl}/audio/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}async request(e,t){let r=`${this.baseUrl}${e}`,n=await this.fetchImpl(r,{...t,headers:{...t?.headers,Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}),p=await n.json().catch(()=>({ok:!1,data:null,error:"Invalid JSON response from server"}));if(!n.ok||!p.ok){let l=p.error||`HTTP Error ${n.status}`;switch(n.status){case 401:case 403:throw new i(l);case 404:throw new c(l);case 429:throw new a(l);default:throw new o(l,n.status,p)}}return p}};0&&(module.exports={AuthenticationError,NotFoundError,RateLimitError,ShobdoClient,ShobdoError});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { ShobdoClient } from \"./client\";\nexport type { ClientConfig } from \"./client\";\nexport * from \"./types\";\nexport * from \"./errors\";\n","export class ShobdoError extends Error {\n public status: number;\n public details?: any;\n\n constructor(message: string, status: number, details?: any) {\n super(message);\n this.name = \"ShobdoError\";\n this.status = status;\n this.details = details;\n }\n}\n\nexport class AuthenticationError extends ShobdoError {\n constructor(message: string = \"Authentication failed. Check your API key.\") {\n super(message, 401);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class RateLimitError extends ShobdoError {\n constructor(message: string = \"Rate limit exceeded. Please upgrade your plan.\") {\n super(message, 429);\n this.name = \"RateLimitError\";\n }\n}\n\nexport class NotFoundError extends ShobdoError {\n constructor(message: string = \"Resource not found.\") {\n super(message, 404);\n this.name = \"NotFoundError\";\n }\n}\n","import { ApiResponse, FullEntry, SearchOptions, SearchResult } from \"./types\";\nimport { AuthenticationError, NotFoundError, RateLimitError, ShobdoError } from \"./errors\";\n\nexport interface ClientConfig {\n /** The Shobdo API key */\n apiKey: string;\n /** Optional base URL (defaults to https://shobdo.me/api/v1) */\n baseUrl?: string;\n /** Optional custom fetch implementation */\n fetch?: typeof fetch;\n}\n\nexport class ShobdoClient {\n private apiKey: string;\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: ClientConfig) {\n if (!config.apiKey) {\n throw new Error(\"Shobdo API key is required\");\n }\n this.apiKey = config.apiKey;\n this.baseUrl = config.baseUrl || \"https://shobdo.me/api/v1\";\n \n // Use native fetch by default, or fallback to the provided fetch\n if (config.fetch) {\n this.fetchImpl = config.fetch;\n } else if (typeof fetch !== \"undefined\") {\n this.fetchImpl = fetch;\n } else {\n throw new Error(\"No global fetch API found. Please provide a custom fetch implementation in ClientConfig.\");\n }\n }\n\n /**\n * Search across all available dictionaries\n * @param query The search term\n * @param options Search filters and pagination\n */\n async search(query: string, options?: SearchOptions): Promise<ApiResponse<SearchResult[]>> {\n const params = new URLSearchParams({ q: query });\n \n if (options) {\n if (options.limit !== undefined) params.append(\"limit\", options.limit.toString());\n if (options.offset !== undefined) params.append(\"offset\", options.offset.toString());\n if (options.lang) params.append(\"lang\", options.lang);\n if (options.source) params.append(\"source\", options.source);\n if (options.matchType) params.append(\"matchType\", options.matchType);\n }\n\n return this.request<SearchResult[]>(`/search?${params.toString()}`);\n }\n\n /**\n * Retrieve a full dictionary entry by its unique ID\n * @param source The dictionary ID\n * @param id The entry ID\n */\n async getEntryById(source: string, id: string): Promise<ApiResponse<FullEntry>> {\n return this.request<FullEntry>(`/entry/${encodeURIComponent(source)}/${encodeURIComponent(id)}`);\n }\n\n /**\n * Look up a dictionary entry by word string\n * @param source The dictionary ID\n * @param word The word to look up\n */\n async getEntryByWord(source: string, word: string): Promise<ApiResponse<FullEntry>> {\n return this.request<FullEntry>(`/entry/${encodeURIComponent(source)}/word/${encodeURIComponent(word)}`);\n }\n\n /**\n * Get the direct URL to the pronunciation audio for an entry\n * @param source The dictionary ID\n * @param lexid The entry ID\n * @returns The full URL to the audio endpoint (which redirects to the CDN)\n */\n getAudioUrl(source: string, lexid: string): string {\n return `${this.baseUrl}/audio/${encodeURIComponent(source)}/${encodeURIComponent(lexid)}`;\n }\n\n private async request<T>(path: string, init?: RequestInit): Promise<ApiResponse<T>> {\n const url = `${this.baseUrl}${path}`;\n \n const response = await this.fetchImpl(url, {\n ...init,\n headers: {\n ...init?.headers,\n \"Authorization\": `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n const data: ApiResponse<T> = await response.json().catch(() => ({\n ok: false,\n data: null as any,\n error: \"Invalid JSON response from server\"\n }));\n\n if (!response.ok || !data.ok) {\n const errorMessage = data.error || `HTTP Error ${response.status}`;\n \n switch (response.status) {\n case 401:\n case 403:\n throw new AuthenticationError(errorMessage);\n case 404:\n throw new NotFoundError(errorMessage);\n case 429:\n throw new RateLimitError(errorMessage);\n default:\n throw new ShobdoError(errorMessage, response.status, data);\n }\n }\n\n return data;\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,iBAAAC,EAAA,gBA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,SAAS,GAG9D,KAAK,QAAwB,WAAWC,EAAO,SAAS,CAAC,EAAE,CACpE,CAOA,MAAM,aAAaC,EAAgBC,EAA6C,CAC9E,OAAO,KAAK,QAAmB,UAAU,mBAAmBD,CAAM,CAAC,IAAI,mBAAmBC,CAAE,CAAC,EAAE,CACjG,CAOA,MAAM,eAAeD,EAAgBE,EAA+C,CAClF,OAAO,KAAK,QAAmB,UAAU,mBAAmBF,CAAM,CAAC,SAAS,mBAAmBE,CAAI,CAAC,EAAE,CACxG,CAQA,YAAYF,EAAgBG,EAAuB,CACjD,MAAO,GAAG,KAAK,OAAO,UAAU,mBAAmBH,CAAM,CAAC,IAAI,mBAAmBG,CAAK,CAAC,EACzF,CAEA,MAAc,QAAWC,EAAcC,EAA6C,CAClF,IAAMC,EAAM,GAAG,KAAK,OAAO,GAAGF,CAAI,GAE5BG,EAAW,MAAM,KAAK,UAAUD,EAAK,CACzC,GAAGD,EACH,QAAS,CACP,GAAGA,GAAM,QACT,cAAiB,UAAU,KAAK,MAAM,GACtC,eAAgB,kBAClB,CACF,CAAC,EAEKG,EAAuB,MAAMD,EAAS,KAAK,EAAE,MAAM,KAAO,CAC9D,GAAI,GACJ,KAAM,KACN,MAAO,mCACT,EAAE,EAEF,GAAI,CAACA,EAAS,IAAM,CAACC,EAAK,GAAI,CAC5B,IAAMC,EAAeD,EAAK,OAAS,cAAcD,EAAS,MAAM,GAEhE,OAAQA,EAAS,OAAQ,CACvB,IAAK,KACL,IAAK,KACH,MAAM,IAAIG,EAAoBD,CAAY,EAC5C,IAAK,KACH,MAAM,IAAIE,EAAcF,CAAY,EACtC,IAAK,KACH,MAAM,IAAIG,EAAeH,CAAY,EACvC,QACE,MAAM,IAAII,EAAYJ,EAAcF,EAAS,OAAQC,CAAI,CAC7D,CACF,CAEA,OAAOA,CACT,CACF","names":["index_exports","__export","AuthenticationError","NotFoundError","RateLimitError","ShobdoClient","ShobdoError","__toCommonJS","ShobdoError","message","status","details","AuthenticationError","RateLimitError","NotFoundError","ShobdoClient","config","query","options","params","source","id","word","lexid","path","init","url","response","data","errorMessage","AuthenticationError","NotFoundError","RateLimitError","ShobdoError"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=class extends Error{status;details;constructor(e,t,r){super(e),this.name="ShobdoError",this.status=t,this.details=r}},c=class extends s{constructor(e="Authentication failed. Check your API key."){super(e,401),this.name="AuthenticationError"}},p=class extends s{constructor(e="Rate limit exceeded. Please upgrade your plan."){super(e,429),this.name="RateLimitError"}},l=class extends s{constructor(e="Resource not found."){super(e,404),this.name="NotFoundError"}};var h=class{apiKey;baseUrl;fetchImpl;constructor(e){if(!e.apiKey)throw new Error("Shobdo API key is required");if(this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||"https://shobdo.me/api/v1",e.fetch)this.fetchImpl=e.fetch;else if(typeof fetch<"u")this.fetchImpl=fetch;else throw new Error("No global fetch API found. Please provide a custom fetch implementation in ClientConfig.")}async search(e,t){let r=new URLSearchParams({q:e});return t&&(t.limit!==void 0&&r.append("limit",t.limit.toString()),t.offset!==void 0&&r.append("offset",t.offset.toString()),t.lang&&r.append("lang",t.lang),t.source&&r.append("source",t.source),t.matchType&&r.append("matchType",t.matchType)),this.request(`/search?${r.toString()}`)}async getEntryById(e,t){return this.request(`/entry/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async getEntryByWord(e,t){return this.request(`/entry/${encodeURIComponent(e)}/word/${encodeURIComponent(t)}`)}getAudioUrl(e,t){return`${this.baseUrl}/audio/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}async request(e,t){let r=`${this.baseUrl}${e}`,n=await this.fetchImpl(r,{...t,headers:{...t?.headers,Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}),i=await n.json().catch(()=>({ok:!1,data:null,error:"Invalid JSON response from server"}));if(!n.ok||!i.ok){let a=i.error||`HTTP Error ${n.status}`;switch(n.status){case 401:case 403:throw new c(a);case 404:throw new l(a);case 429:throw new p(a);default:throw new s(a,n.status,i)}}return i}};export{c as AuthenticationError,l as NotFoundError,p as RateLimitError,h as ShobdoClient,s as ShobdoError};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["export class ShobdoError extends Error {\n public status: number;\n public details?: any;\n\n constructor(message: string, status: number, details?: any) {\n super(message);\n this.name = \"ShobdoError\";\n this.status = status;\n this.details = details;\n }\n}\n\nexport class AuthenticationError extends ShobdoError {\n constructor(message: string = \"Authentication failed. Check your API key.\") {\n super(message, 401);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class RateLimitError extends ShobdoError {\n constructor(message: string = \"Rate limit exceeded. Please upgrade your plan.\") {\n super(message, 429);\n this.name = \"RateLimitError\";\n }\n}\n\nexport class NotFoundError extends ShobdoError {\n constructor(message: string = \"Resource not found.\") {\n super(message, 404);\n this.name = \"NotFoundError\";\n }\n}\n","import { ApiResponse, FullEntry, SearchOptions, SearchResult } from \"./types\";\nimport { AuthenticationError, NotFoundError, RateLimitError, ShobdoError } from \"./errors\";\n\nexport interface ClientConfig {\n /** The Shobdo API key */\n apiKey: string;\n /** Optional base URL (defaults to https://shobdo.me/api/v1) */\n baseUrl?: string;\n /** Optional custom fetch implementation */\n fetch?: typeof fetch;\n}\n\nexport class ShobdoClient {\n private apiKey: string;\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: ClientConfig) {\n if (!config.apiKey) {\n throw new Error(\"Shobdo API key is required\");\n }\n this.apiKey = config.apiKey;\n this.baseUrl = config.baseUrl || \"https://shobdo.me/api/v1\";\n \n // Use native fetch by default, or fallback to the provided fetch\n if (config.fetch) {\n this.fetchImpl = config.fetch;\n } else if (typeof fetch !== \"undefined\") {\n this.fetchImpl = fetch;\n } else {\n throw new Error(\"No global fetch API found. Please provide a custom fetch implementation in ClientConfig.\");\n }\n }\n\n /**\n * Search across all available dictionaries\n * @param query The search term\n * @param options Search filters and pagination\n */\n async search(query: string, options?: SearchOptions): Promise<ApiResponse<SearchResult[]>> {\n const params = new URLSearchParams({ q: query });\n \n if (options) {\n if (options.limit !== undefined) params.append(\"limit\", options.limit.toString());\n if (options.offset !== undefined) params.append(\"offset\", options.offset.toString());\n if (options.lang) params.append(\"lang\", options.lang);\n if (options.source) params.append(\"source\", options.source);\n if (options.matchType) params.append(\"matchType\", options.matchType);\n }\n\n return this.request<SearchResult[]>(`/search?${params.toString()}`);\n }\n\n /**\n * Retrieve a full dictionary entry by its unique ID\n * @param source The dictionary ID\n * @param id The entry ID\n */\n async getEntryById(source: string, id: string): Promise<ApiResponse<FullEntry>> {\n return this.request<FullEntry>(`/entry/${encodeURIComponent(source)}/${encodeURIComponent(id)}`);\n }\n\n /**\n * Look up a dictionary entry by word string\n * @param source The dictionary ID\n * @param word The word to look up\n */\n async getEntryByWord(source: string, word: string): Promise<ApiResponse<FullEntry>> {\n return this.request<FullEntry>(`/entry/${encodeURIComponent(source)}/word/${encodeURIComponent(word)}`);\n }\n\n /**\n * Get the direct URL to the pronunciation audio for an entry\n * @param source The dictionary ID\n * @param lexid The entry ID\n * @returns The full URL to the audio endpoint (which redirects to the CDN)\n */\n getAudioUrl(source: string, lexid: string): string {\n return `${this.baseUrl}/audio/${encodeURIComponent(source)}/${encodeURIComponent(lexid)}`;\n }\n\n private async request<T>(path: string, init?: RequestInit): Promise<ApiResponse<T>> {\n const url = `${this.baseUrl}${path}`;\n \n const response = await this.fetchImpl(url, {\n ...init,\n headers: {\n ...init?.headers,\n \"Authorization\": `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n const data: ApiResponse<T> = await response.json().catch(() => ({\n ok: false,\n data: null as any,\n error: \"Invalid JSON response from server\"\n }));\n\n if (!response.ok || !data.ok) {\n const errorMessage = data.error || `HTTP Error ${response.status}`;\n \n switch (response.status) {\n case 401:\n case 403:\n throw new AuthenticationError(errorMessage);\n case 404:\n throw new NotFoundError(errorMessage);\n case 429:\n throw new RateLimitError(errorMessage);\n default:\n throw new ShobdoError(errorMessage, response.status, data);\n }\n }\n\n return data;\n }\n}\n"],"mappings":"AAAO,IAAMA,EAAN,cAA0B,KAAM,CAC9B,OACA,QAEP,YAAYC,EAAiBC,EAAgBC,EAAe,CAC1D,MAAMF,CAAO,EACb,KAAK,KAAO,cACZ,KAAK,OAASC,EACd,KAAK,QAAUC,CACjB,CACF,EAEaC,EAAN,cAAkCJ,CAAY,CACnD,YAAYC,EAAkB,6CAA8C,CAC1E,MAAMA,EAAS,GAAG,EAClB,KAAK,KAAO,qBACd,CACF,EAEaI,EAAN,cAA6BL,CAAY,CAC9C,YAAYC,EAAkB,iDAAkD,CAC9E,MAAMA,EAAS,GAAG,EAClB,KAAK,KAAO,gBACd,CACF,EAEaK,EAAN,cAA4BN,CAAY,CAC7C,YAAYC,EAAkB,sBAAuB,CACnD,MAAMA,EAAS,GAAG,EAClB,KAAK,KAAO,eACd,CACF,ECnBO,IAAMM,EAAN,KAAmB,CAChB,OACA,QACA,UAER,YAAYC,EAAsB,CAChC,GAAI,CAACA,EAAO,OACV,MAAM,IAAI,MAAM,4BAA4B,EAM9C,GAJA,KAAK,OAASA,EAAO,OACrB,KAAK,QAAUA,EAAO,SAAW,2BAG7BA,EAAO,MACT,KAAK,UAAYA,EAAO,cACf,OAAO,MAAU,IAC1B,KAAK,UAAY,UAEjB,OAAM,IAAI,MAAM,0FAA0F,CAE9G,CAOA,MAAM,OAAOC,EAAeC,EAA+D,CACzF,IAAMC,EAAS,IAAI,gBAAgB,CAAE,EAAGF,CAAM,CAAC,EAE/C,OAAIC,IACEA,EAAQ,QAAU,QAAWC,EAAO,OAAO,QAASD,EAAQ,MAAM,SAAS,CAAC,EAC5EA,EAAQ,SAAW,QAAWC,EAAO,OAAO,SAAUD,EAAQ,OAAO,SAAS,CAAC,EAC/EA,EAAQ,MAAMC,EAAO,OAAO,OAAQD,EAAQ,IAAI,EAChD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["ShobdoError","message","status","details","AuthenticationError","RateLimitError","NotFoundError","ShobdoClient","config","query","options","params","source","id","word","lexid","path","init","url","response","data","errorMessage","AuthenticationError","NotFoundError","RateLimitError","ShobdoError"]}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type LanguageCode = "en" | "de" | "fr" | "es" | "it" | "pt" | "ru" | "zh" | "ja" | "hi" | "ur" | "bn" | "ar" | "fa" | "my" | "bg" | "el" | "th";
|
|
2
|
+
export interface SearchResult {
|
|
3
|
+
id: string;
|
|
4
|
+
word: string;
|
|
5
|
+
preview: string;
|
|
6
|
+
sourceLang: LanguageCode;
|
|
7
|
+
targetLang: LanguageCode | null;
|
|
8
|
+
dictionaryId: string;
|
|
9
|
+
dictionaryName: string;
|
|
10
|
+
partOfSpeech?: string;
|
|
11
|
+
phonetic?: string;
|
|
12
|
+
hasAudio: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface FullEntry {
|
|
15
|
+
id: string;
|
|
16
|
+
word: string;
|
|
17
|
+
htmlContent: string;
|
|
18
|
+
plainText: string;
|
|
19
|
+
sourceLang: LanguageCode;
|
|
20
|
+
targetLang: LanguageCode | null;
|
|
21
|
+
dictionaryId: string;
|
|
22
|
+
dictionaryName: string;
|
|
23
|
+
partOfSpeech?: string;
|
|
24
|
+
phonetic?: string;
|
|
25
|
+
synonyms?: string[];
|
|
26
|
+
antonyms?: string[];
|
|
27
|
+
examples?: string[];
|
|
28
|
+
hasAudio: boolean;
|
|
29
|
+
audioUrl?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ResponseMeta {
|
|
32
|
+
total?: number;
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
took_ms?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface ApiResponse<T> {
|
|
38
|
+
ok: boolean;
|
|
39
|
+
data: T;
|
|
40
|
+
meta?: ResponseMeta;
|
|
41
|
+
error?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface SearchOptions {
|
|
44
|
+
limit?: number;
|
|
45
|
+
offset?: number;
|
|
46
|
+
lang?: string;
|
|
47
|
+
source?: string;
|
|
48
|
+
matchType?: 'exact' | 'prefix' | 'contains';
|
|
49
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shobdo/js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official JavaScript/TypeScript SDK for the Shobdo API",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup && tsc --emitDeclarationOnly",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/shobdo/shobdo-js.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"shobdo",
|
|
30
|
+
"dictionary",
|
|
31
|
+
"api",
|
|
32
|
+
"sdk"
|
|
33
|
+
],
|
|
34
|
+
"author": "Shobdo",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^26.1.1",
|
|
38
|
+
"tsup": "^8.5.1",
|
|
39
|
+
"typescript": "^7.0.2",
|
|
40
|
+
"vitest": "^4.1.10"
|
|
41
|
+
}
|
|
42
|
+
}
|