-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "wpcom-proxy-request: Return Promise if no callback specified …
- Loading branch information
Showing
15 changed files
with
69 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ Dockerfile | |
/apps/*/dist/ | ||
/apps/*/types/ | ||
/packages/*/dist/ | ||
/packages/*/types/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
declare module 'wpcom-proxy-request' { | ||
type WpcomRequestParams = import('./src/utils/wpcom-wrapper').WpcomRequestParams; | ||
export function reloadProxy(): void; | ||
export default function wpcomProxyRequest( | ||
params: WpcomRequestParams, | ||
callback: Function | ||
): XMLHttpRequest; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './wpcom-wrapper'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import wpcomProxyRequest, { reloadProxy } from 'wpcom-proxy-request'; | ||
import debugFactory from 'debug'; | ||
|
||
const debug = debugFactory( 'data-stores:utils:wpcom-wrapper' ); | ||
|
||
export interface WpcomClientCredentials { | ||
client_id: string; | ||
client_secret: string; | ||
} | ||
|
||
export interface WpcomRequestParams { | ||
path?: string; | ||
method?: string; | ||
apiVersion?: string; | ||
body?: object; | ||
token?: string; | ||
metaAPI?: { | ||
accessAllUsersBlogs?: boolean; | ||
}; | ||
} | ||
|
||
export function wpcomRequest< T >( params: WpcomRequestParams ): Promise< T > { | ||
return new Promise( ( resolve, reject ) => { | ||
wpcomProxyRequest( params, ( err: Error, res: T ) => { | ||
debug( res ); | ||
err ? reject( err ) : resolve( res ); | ||
} ); | ||
} ); | ||
} | ||
/* | ||
* Reloading the proxy ensures that the proxy iframe has set the correct API cookie. | ||
* This is particularly useful for making authenticated API requests | ||
* *after* the user has logged in or signed up without the need for a hard browser refresh. | ||
*/ | ||
export function reloadWpcomProxy(): void { | ||
reloadProxy(); | ||
} | ||
|
||
wpcomProxyRequest( { metaAPI: { accessAllUsersBlogs: true } }, ( error: Error ) => { | ||
if ( error ) { | ||
throw error; | ||
} | ||
debug( 'Proxy now running in "access all user\'s blogs" mode' ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.