generated from vtex-apps/service-example
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from vtex/schema-client
Feature / Schema client
- Loading branch information
Showing
9 changed files
with
78 additions
and
6 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
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,33 @@ | ||
import type { InstanceOptions, IOContext, RequestConfig } from '@vtex/api' | ||
import { ExternalClient } from '@vtex/api' | ||
|
||
const routes = { | ||
schemas: (dataEntity: string) => `/dataentities/${dataEntity}/schemas`, | ||
delete: (dataEntity: string, schemaName: string) => | ||
`dataentities/${dataEntity}/schemas/${schemaName}`, | ||
} | ||
|
||
export default class SchemasClient extends ExternalClient { | ||
constructor(context: IOContext, options?: InstanceOptions) { | ||
super(`http://${context.account}.myvtex.com/api`, context, { | ||
...options, | ||
headers: { | ||
...options?.headers, | ||
VtexIdclientAutCookie: context.authToken, | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
} | ||
|
||
public getSchemas(dataEntity: string, config?: RequestConfig): Promise<any> { | ||
return this.http.get(routes.schemas(dataEntity), config) | ||
} | ||
|
||
public deleteSchemas( | ||
dataEntity: string, | ||
schemaName: string, | ||
config?: RequestConfig | ||
): Promise<any> { | ||
return this.http.delete(routes.delete(dataEntity, schemaName), config) | ||
} | ||
} |
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,22 @@ | ||
export async function getSchemas(ctx: Context, next: () => Promise<unknown>) { | ||
const { | ||
clients: { schemas }, | ||
vtex: { logger }, | ||
} = ctx | ||
|
||
try { | ||
const schemaList = await schemas.getSchemas('vtex_affiliates_Affiliates') | ||
|
||
console.info('testing', schemaList) | ||
ctx.message = `Schema list retrieved` | ||
ctx.status = 200 | ||
} catch (err) { | ||
logger.error({ | ||
metric: 'get-affiliate-schema', | ||
message: err.message, | ||
}) | ||
throw new Error('Error getting affiliate schemas') | ||
} | ||
|
||
await next() | ||
} |
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 |
---|---|---|
|
@@ -1658,10 +1658,10 @@ | |
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.3.tgz#781d360c282436494b32fe7d9f7f8e64b3118aa3" | ||
integrity sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw== | ||
|
||
"@vtex/[email protected].21": | ||
version "6.45.21" | ||
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.21.tgz#2f5ea4a14dfbf426f6fbad140caf23c89060b313" | ||
integrity sha512-Yo4og5bSM1n5WSQ3u8nsqEHicvxdyOZX3uA0KtQHbS4frSeA4hcGRuupsFHQ13eZZGMy4OR4fJO7ZQfkj8qLhQ== | ||
"@vtex/[email protected].22": | ||
version "6.45.22" | ||
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.22.tgz#fa9bbfde1a4d4fbbaf6cce9f6dbc9bb9ee929ba3" | ||
integrity sha512-g5cGUDhF4FADgSMpQmce/bnIZumwGlPG2cabwbQKIQ+cCFMZqOEM/n+YQb1+S8bCyHkzW3u/ZABoyCKi5/nxxg== | ||
dependencies: | ||
"@types/koa" "^2.11.0" | ||
"@types/koa-compose" "^3.2.3" | ||
|
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