This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom apis): adds the custom apis endpoint (#929)
* feat(custom apis): adds the custom apis endpoint * updated export * updated validation * updated validation and its fields to optional * updated name for validation * updated to use slug
- Loading branch information
1 parent
d584d96
commit 39135f4
Showing
4 changed files
with
239 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,117 @@ | ||
import CRUDExtend from '../extends/crud' | ||
|
||
import { buildURL } from '../utils/helpers' | ||
|
||
class CustomApisEndpoint extends CRUDExtend { | ||
constructor(endpoint) { | ||
super(endpoint) | ||
|
||
this.endpoint = 'settings/extensions/custom-apis' | ||
this.entriesEndpoint = 'extensions' | ||
} | ||
|
||
Create(body) { | ||
return this.request.send( | ||
this.endpoint, | ||
'POST', | ||
body | ||
) | ||
} | ||
|
||
Update(id, body) { | ||
return this.request.send( | ||
`${this.endpoint}/${id}`, | ||
'PUT', | ||
body | ||
) | ||
} | ||
|
||
GetFields(customApiId) { | ||
const { limit, offset, sort } = this | ||
|
||
return this.request.send( | ||
buildURL(`${this.endpoint}/${customApiId}/fields`, { | ||
limit, | ||
offset, | ||
sort | ||
}), | ||
'GET' | ||
) | ||
} | ||
|
||
GetField(customApiId, customApiFieldId) { | ||
return this.request.send( | ||
`${this.endpoint}/${customApiId}/fields/${customApiFieldId}`, | ||
'GET' | ||
) | ||
} | ||
|
||
CreateField(customApiId, body) { | ||
return this.request.send( | ||
`${this.endpoint}/${customApiId}/fields`, | ||
'POST', | ||
body | ||
) | ||
} | ||
|
||
UpdateField(customApiId, customApiFieldId, body) { | ||
return this.request.send( | ||
`${this.endpoint}/${customApiId}/fields/${customApiFieldId}`, | ||
'PUT', | ||
body | ||
) | ||
} | ||
|
||
DeleteField(customApiId, customApiFieldId) { | ||
return this.request.send( | ||
`${this.endpoint}/${customApiId}/fields/${customApiFieldId}`, | ||
'DELETE' | ||
) | ||
} | ||
|
||
GetEntries(customApiSlug) { | ||
const { limit, offset, sort, filter } = this | ||
|
||
return this.request.send( | ||
buildURL(`${this.entriesEndpoint}/${customApiSlug}`, { | ||
limit, | ||
offset, | ||
sort, | ||
filter | ||
}), | ||
'GET' | ||
) | ||
} | ||
|
||
GetEntry(customApiSlug, customApiEntryId) { | ||
return this.request.send( | ||
`${this.entriesEndpoint}/${customApiSlug}/${customApiEntryId}`, | ||
'GET' | ||
) | ||
} | ||
|
||
CreateEntry(customApiSlug, body) { | ||
return this.request.send( | ||
`${this.entriesEndpoint}/${customApiSlug}`, | ||
'POST', | ||
body | ||
) | ||
} | ||
|
||
UpdateEntry(customApiSlug, customApiEntryId, body) { | ||
return this.request.send( | ||
`${this.entriesEndpoint}/${customApiSlug}/${customApiEntryId}`, | ||
'PUT', | ||
body | ||
) | ||
} | ||
|
||
DeleteEntry(customApiSlug, customApiEntryId) { | ||
return this.request.send( | ||
`${this.entriesEndpoint}/${customApiSlug}/${customApiEntryId}`, | ||
'DELETE' | ||
) | ||
} | ||
} | ||
|
||
export default CustomApisEndpoint |
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,117 @@ | ||
/** | ||
* Commerce Extensions | ||
* Description: Commerce Extensions allows for the creation of Custom APIs that can manage large, private data sets efficiently, offering both simple and complex multidimensional filtering options. | ||
* DOCS: https://elasticpath.dev/docs/commerce-cloud/commerce-extensions/overview | ||
*/ | ||
|
||
import { Identifiable, Resource, ResourcePage } from './core'; | ||
|
||
|
||
export interface CustomApiBase { | ||
name: string | ||
description: string | ||
api_type: string | ||
type: string | ||
slug: string | ||
} | ||
|
||
export interface CustomApi extends Identifiable, CustomApiBase { | ||
links: { | ||
self: string | ||
} | ||
meta: { | ||
timestamps: { | ||
created_at: string | ||
updated_at: string | ||
} | ||
} | ||
} | ||
|
||
export type CustomFieldValidation = | ||
| { string: { min_length?: number, max_length?: number, regex?: string, allow_null_values?: boolean } } | ||
| { integer: { min_value?: number, max_value?: number, allow_null_values?: boolean } } | ||
| { float: { min_value?: number, max_value?: number, allow_null_values?: boolean } } | ||
| { boolean: { allow_null_values?: boolean } } | ||
|
||
export interface CustomApiFieldBase { | ||
name: string | ||
description: string | ||
field_type: string | ||
type: string | ||
slug: string | ||
validation?: CustomFieldValidation | ||
} | ||
|
||
export interface CustomApiField extends Identifiable, CustomApiFieldBase { | ||
links: { | ||
self: string | ||
} | ||
meta: { | ||
timestamps: { | ||
created_at: string | ||
updated_at: string | ||
} | ||
} | ||
} | ||
|
||
export interface CustomApisEndpoint { | ||
endpoint: 'settings/extensions/custom-apis' | ||
entriesEndpoint: 'extensions' | ||
|
||
All(token?: string): Promise<ResourcePage<CustomApi>> | ||
|
||
Get(id: string, token?: string): Promise<Resource<CustomApi>> | ||
|
||
Filter(filter: any): CustomApisEndpoint | ||
|
||
Limit(value: number): CustomApisEndpoint | ||
|
||
Offset(value: number): CustomApisEndpoint | ||
|
||
Sort(value: string): CustomApisEndpoint | ||
|
||
Create(body: CustomApiBase): Promise<Resource<CustomApi>> | ||
|
||
Update( | ||
id: string, | ||
body: Partial<CustomApiBase>, | ||
token?: string | ||
): Promise<Resource<CustomApi>> | ||
|
||
Delete(id: string): Promise<{}> | ||
|
||
GetFields<T = any>(customApiId: string): Promise<T> | ||
|
||
GetField<T = any>(customApiId: string, customApiFieldId:string): Promise<T> | ||
|
||
CreateField<RequestBody = CustomApiFieldBase, ResponseBody = CustomApiField>( | ||
customApiId: string, | ||
body: RequestBody | ||
): Promise<ResponseBody> | ||
|
||
UpdateField<RequestBody = CustomApiFieldBase, ResponseBody = CustomApiField>( | ||
customApiId: string, | ||
customApiFieldId: string, | ||
body: RequestBody | ||
): Promise<ResponseBody> | ||
|
||
DeleteField<T = any>(customApiId: string, customApiFieldId: string): Promise<T> | ||
|
||
GetEntries<T = any>(customApiSlug: string): Promise<T> | ||
|
||
GetEntry<T = any>(customApiSlug: string, customApiEntryId: string): Promise<T> | ||
|
||
CreateEntry<RequestBody = any, ResponseBody = any>( | ||
customApiSlug: string, | ||
body: RequestBody | ||
): Promise<ResponseBody> | ||
|
||
UpdateEntry<RequestBody = any, ResponseBody = any>( | ||
customApiSlug: string, | ||
customApiEntryId: string, | ||
body: RequestBody | ||
): Promise<ResponseBody> | ||
|
||
DeleteEntry<T = any>(customApiSlug: string, customApiEntryId: string): Promise<T> | ||
|
||
} |