-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a skeleton of new data feeds endpoint
- Loading branch information
Showing
5 changed files
with
215 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { | ||
Http, | ||
squashAndPreparePositionalArguments | ||
} from '@spree/core-api-v2-sdk' | ||
import type { | ||
NoContentResponse, | ||
NoContentResult | ||
} from '@spree/core-api-v2-sdk' | ||
import type { | ||
IDataFeed, | ||
IDataFeedResult, | ||
IDataFeeds, | ||
IDataFeedsResult, | ||
ListOptions, | ||
ShowOptions, | ||
CreateOptions, | ||
UpdateOptions, | ||
RemoveOptions | ||
} from '../interfaces/DataFeeds' | ||
import routes from '../routes' | ||
|
||
export default class DataFeeds extends Http { | ||
/** | ||
* Returns a list of all Data Feeds. | ||
* | ||
* **Required token:** [Bearer token](../pages/tokens.html#bearer-token) | ||
* | ||
* **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) | ||
* | ||
* **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) | ||
* | ||
* **Example:** | ||
* ```ts | ||
* const response = await client.dataFeeds.list({ | ||
* bearer_token: '7381273269536713689562374856' | ||
* }) | ||
* ``` | ||
*/ | ||
public async list(options: ListOptions): Promise<IDataFeedsResult> { | ||
console.log(options) | ||
const { token, params } = squashAndPreparePositionalArguments([options], []) | ||
|
||
return await this.spreeResponse<IDataFeeds>('get', routes.dataFeeds(), token, params) | ||
} | ||
|
||
/** | ||
* Returns a single Data Feed by its ID. | ||
* | ||
* **Required token:** [Bearer token](../pages/tokens.html#bearer-token) | ||
* | ||
* **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) | ||
* | ||
* **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) | ||
* | ||
* **Example:** | ||
* ```ts | ||
* const response = await client.dataFeeds.show({ | ||
* bearer_token: '7381273269536713689562374856' | ||
* id: '1' | ||
* }) | ||
* ``` | ||
*/ | ||
public async show(options: ShowOptions): Promise<IDataFeedResult> { | ||
const { id, token, params } = squashAndPreparePositionalArguments([options], ['id']) | ||
|
||
return await this.spreeResponse<IDataFeed>('get', routes.dataFeed(id), token, params) | ||
} | ||
|
||
/** | ||
* Creates a new Data Feed and returns its attributes. | ||
* | ||
* **Required token:** [Bearer token](../pages/tokens.html#bearer-token) | ||
* | ||
* **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) | ||
* | ||
* **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) | ||
* | ||
* **Example:** | ||
* ```ts | ||
* const response = await client.dataFeeds.create({ | ||
* bearer_token: '7381273269536713689562374856', | ||
* dataFeed: { | ||
* provider: 'google', | ||
* name: 'Google data feed' | ||
* } | ||
* }) | ||
* ``` | ||
*/ | ||
public async create(options: CreateOptions): Promise<IDataFeedResult> { | ||
const { token, params } = squashAndPreparePositionalArguments([options], []) | ||
|
||
return await this.spreeResponse<IDataFeed>('post', routes.dataFeeds(), token, params) | ||
} | ||
|
||
/** | ||
* Update selected Data Feed. | ||
* | ||
* **Required token:** [Bearer token](../pages/tokens.html#bearer-token) | ||
* | ||
* **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) | ||
* | ||
* **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) | ||
* | ||
* **Example:** | ||
* ```ts | ||
* const response = await client.dataFeeds.update({ | ||
* bearer_token: '7381273269536713689562374856', | ||
* id: '1', | ||
* dataFeed: { | ||
* name: 'New feed name' | ||
* } | ||
* }) | ||
* ``` | ||
*/ | ||
public async update(options: UpdateOptions): Promise<IDataFeedResult> { | ||
const { id, token, params } = squashAndPreparePositionalArguments([options], ['id']) | ||
|
||
return await this.spreeResponse<IDataFeed>('patch', routes.dataFeed(id), token, params) | ||
} | ||
|
||
/** | ||
* This endpoint removes the specified Data Feed. | ||
* | ||
* **Required token:** [Bearer token](../pages/tokens.html#bearer-token) | ||
* | ||
* **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) | ||
* | ||
* **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) | ||
* | ||
* **Example:** | ||
* ```ts | ||
* const response = await client.dataFeeds.remove({ | ||
* bearer_token: '7381273269536713689562374856', | ||
* id: '1' | ||
* }) | ||
* ``` | ||
*/ | ||
public async remove(options: RemoveOptions): Promise<NoContentResult> { | ||
const { id, token, params } = squashAndPreparePositionalArguments([options], ['id']) | ||
|
||
return await this.spreeResponse<NoContentResponse>('delete', routes.dataFeed(id), token, params) | ||
} | ||
} |
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,66 @@ | ||
import type { | ||
JsonApiDocument, | ||
JsonApiListResponse, | ||
JsonApiSingleResponse, | ||
ResultResponse, | ||
WithCommonOptions | ||
} from '@spree/core-api-v2-sdk' | ||
|
||
export interface DataFeedAttr { | ||
spree_store_id: number | ||
name: string | ||
provider: string | ||
uuid: string | ||
enabled: boolean | ||
} | ||
|
||
export interface DataFeed extends JsonApiDocument { | ||
type: string | ||
id: string | ||
attributes: DataFeedAttr | ||
} | ||
|
||
export interface DataFeedParams { | ||
data_feed_setting: { | ||
spree_store_id: number | ||
name: string | ||
provider: string | ||
enabled: boolean | ||
} | ||
} | ||
|
||
export interface IDataFeed extends JsonApiSingleResponse { | ||
data: DataFeed | ||
} | ||
|
||
export interface IDataFeeds extends JsonApiListResponse { | ||
data: DataFeed[] | ||
} | ||
|
||
export interface IDataFeedResult extends ResultResponse<IDataFeed> {} | ||
|
||
export interface IDataFeedsResult extends ResultResponse<IDataFeeds> {} | ||
|
||
export type ListOptions = WithCommonOptions< | ||
{ suggestToken: true; onlyAccountToken: true; suggestQuery: true } | ||
> | ||
|
||
export type ShowOptions = WithCommonOptions< | ||
{ suggestToken: true; onlyAccountToken: true; suggestQuery: true }, | ||
{ id: string } | ||
> | ||
|
||
export type CreateOptions = WithCommonOptions< | ||
{ suggestToken: true; onlyAccountToken: true; suggestQuery: true }, | ||
DataFeedParams | ||
> | ||
|
||
export type UpdateOptions = WithCommonOptions< | ||
{ suggestToken: true; onlyAccountToken: true; suggestQuery: true }, | ||
DataFeedParams & { id: string } | ||
> | ||
|
||
export type RemoveOptions = WithCommonOptions< | ||
{ suggestToken: true; onlyAccountToken: true }, | ||
{ id: string } | ||
> |
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