diff --git a/README.md b/README.md index 752bc66..25f6180 100644 --- a/README.md +++ b/README.md @@ -72,11 +72,30 @@ const { upload } = createFlickr({ > 💡 Use `examples/oauth.mjs` to quickly set up an OAuth flow and obtain a > set of credentials +## migrating from previous versions + +Previous versions of this SDK depended on [superagent][superagent] for http +requests. This version of the SDK uses node's native `fetch` instead, so ou now +only receive the response body back from an API call. This means **the return +value of an API call will only be the response body, not a superagent Request** + +Migrating existin code looks like this: + +```js +// old +const res = await flickr.test.login() +console.log(res.body) + +// new +const body = await flickr('flickr.test.login') +console.log(body) +``` + ## advanced #### configuring fetch -```ts +```js import { createFlickr, FetchTransport } from 'flickr-sdk' const transport = new FetchTransport({ @@ -90,7 +109,7 @@ const { flickr } = createFlickr('', transport) #### testing -```ts +```js import { createFlickr, MockTransport, NullAuth } from 'flickr-sdk' import * as assert from 'node:assert' diff --git a/src/index.ts b/src/index.ts index bd98fa2..9ed67a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import type { API, APIShape } from "./services/rest/api" import type { Auth, Transport } from "./types" import { APIKeyAuth } from "./auth/api_key" import { OAuthAuth, OAuthConfig } from "./auth/oauth" @@ -8,34 +7,33 @@ import { Upload, UploadService } from "./services/upload" import { Replace, ReplaceService } from "./services/replace" import { FetchTransport } from "./transport/fetch" -export interface FlickrServices { - flickr: Flickr +export interface FlickrServices { + flickr: Flickr upload: Upload replace: Replace } -export interface FlickrServicesWithOAuth - extends FlickrServices { +export interface FlickrServicesWithOAuth extends FlickrServices { // oauth is only defined if the auth method is oauth oauth: OAuthService } -export function createFlickr( +export function createFlickr( apiKey: string, transport?: Transport, -): FlickrServices +): FlickrServices -export function createFlickr( +export function createFlickr( oauthConfig: OAuthConfig, transport?: Transport, -): FlickrServicesWithOAuth +): FlickrServicesWithOAuth -export function createFlickr( +export function createFlickr( auth: A, transport?: Transport, -): A extends OAuthAuth ? FlickrServicesWithOAuth : FlickrServices +): A extends OAuthAuth ? FlickrServicesWithOAuth : FlickrServices -export function createFlickr( +export function createFlickr( auth: string | OAuthConfig | Auth, transport: Transport = new FetchTransport(), ) { @@ -62,7 +60,7 @@ export function createFlickr( } // REST API - const flickr: Flickr = async (method, params) => { + const flickr: Flickr = async (method, params) => { const service = new FlickrService(transport, auth) return service.call(method as string, params as Record) } diff --git a/src/services/rest/api.ts b/src/services/rest/api.ts index 67f9148..822c4fa 100644 --- a/src/services/rest/api.ts +++ b/src/services/rest/api.ts @@ -448,11 +448,7 @@ import type { FlickrUrlsLookupGroupResponse } from "./flickr.urls.lookupGroup.re import type { FlickrUrlsLookupUserParams } from "./flickr.urls.lookupUser" import type { FlickrUrlsLookupUserResponse } from "./flickr.urls.lookupUser.response" -export type APIShape = { - [key: string]: [params: any, response: any] -} - -export type API = APIShape & { +export type API = { "flickr.activity.userComments": [ FlickrActivityUserCommentsParams, FlickrActivityUserCommentsResponse, diff --git a/src/services/rest/index.ts b/src/services/rest/index.ts index 292fbf5..15b9beb 100644 --- a/src/services/rest/index.ts +++ b/src/services/rest/index.ts @@ -1,10 +1,10 @@ import type { Auth, Transport } from "../../types" -import { POST_REGEXP, API, APIShape } from "./api" +import { POST_REGEXP, API } from "./api" import { GET, POST } from "../../params" import { JSONParser } from "../../parser/json" -export interface Flickr { - (method: T, params: A[T][0]): Promise +export interface Flickr { + (method: T, params: API[T][0]): Promise } export class FlickrService {