Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a skeleton of new data feeds endpoint #372

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions packages/sdk-platform/src/endpoints/DataFeeds.ts
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',
* data_feed_setting: {
* 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',
* data_feed_setting: {
* 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)
}
}
2 changes: 2 additions & 0 deletions packages/sdk-platform/src/endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Classifications from './Classifications'
import Countries from './Countries'
import Pages from './Pages'
import Sections from './Sections'
import DataFeeds from './DataFeeds'
import Digitals from './Digitals'
import Links from './Links'
import Items from './Items'
Expand Down Expand Up @@ -50,6 +51,7 @@ export {
Countries,
Pages,
Sections,
DataFeeds,
Digitals,
Links,
Items,
Expand Down
66 changes: 66 additions & 0 deletions packages/sdk-platform/src/interfaces/DataFeeds.ts
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 }
>
2 changes: 2 additions & 0 deletions packages/sdk-platform/src/makeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Countries,
Pages,
Sections,
DataFeeds,
Digitals,
Links,
Items,
Expand Down Expand Up @@ -54,6 +55,7 @@ const endpoints = {
countries: Countries,
pages: Pages,
sections: Sections,
dataFeeds: DataFeeds,
digitals: Digitals,
links: Links,
items: Items,
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk-platform/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const endpoints = {
classificationPath: (id: string) => `${platformPath}/classifications/${encodeURIComponent(id)}`,
countriesPath: (): string => `${platformPath}/countries`,
countryPath: (id: string) => `${platformPath}/countries/${encodeURIComponent(id)}`,
dataFeeds: () => `${platformPath}/data_feed_settings`,
dataFeed: (id: string) => `${platformPath}/data_feed_settings/${encodeURIComponent(id)}`,
pagesPath: (): string => `${platformPath}/cms_pages`,
pagePath: (id: string) => `${platformPath}/cms_pages/${encodeURIComponent(id)}`,
sectionsPath: (): string => `${platformPath}/cms_sections`,
Expand Down