Skip to content

Commit

Permalink
[Core] Add some more exports for use in the other packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Pewtro committed Mar 27, 2024
1 parent cd8a5ee commit 00c0830
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-lies-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blizzard-api/core': patch
---

Add BlizzardNamespaces, ClientOptions, Resource, ResourceResponse, ResourceOptions, ResourceInterface,ProtectedResourceOptions and ProtectedResourceInterface exports.
10 changes: 8 additions & 2 deletions packages/core/src/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface Endpoints {
tw: Endpoint<'tw'>;
}

const endpoints: Endpoints = {
export const endpoints: Endpoints = {
us: {
hostname: 'https://us.api.blizzard.com',
defaultLocale: 'en_US',
Expand All @@ -58,10 +58,16 @@ const endpoints: Endpoints = {
},
};

export interface GetEndpoint<T extends Origins> {
origin: Origins;
locale: (typeof locales)[T][number];
hostname: Endpoint<Origins>['hostname'];
}

export function getEndpoint<T extends Origins>(
origin: T,
locale?: (typeof locales)[typeof origin][number],
): { origin: Origins; locale: (typeof locales)[typeof origin][number]; hostname: Endpoint<Origins>['hostname'] } {
): GetEndpoint<typeof origin> {
const endpoint = endpoints[origin];

return {
Expand Down
18 changes: 16 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
//Resource
export type { BlizzardNamespaces } from './resource.js';
//Endpoint
export type { Origins, Locales } from './endpoint.js';
export { getEndpoint } from './endpoint.js';

//Namespace
export type { BlizzardNamespaces } from './namespace.js';

//Request
export type { ClientOptions } from './request.js';

//Resource
export type {
Resource,
ResourceResponse,
ResourceOptions,
ResourceInterface,
ProtectedResourceOptions,
ProtectedResourceInterface,
} from './resource.js';
8 changes: 8 additions & 0 deletions packages/core/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type BlizzardNamespaces =
| 'profile'
| 'static'
| 'dynamic'
| 'static-classic'
| 'dynamic-classic'
| 'static-classic1x'
| 'dynamic-classic1x';
9 changes: 9 additions & 0 deletions packages/core/src/request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Locales, Origins } from './endpoint';

export interface ClientOptions {
key: string;
secret: string;
origin: Origins;
locale?: Locales;
token?: string;
}
25 changes: 17 additions & 8 deletions packages/core/src/resource.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
export type BlizzardNamespaces =
| 'profile'
| 'static'
| 'dynamic'
| 'static-classic'
| 'dynamic-classic'
| 'static-classic1x'
| 'dynamic-classic1x';
import type { BlizzardNamespaces } from './namespace';
import type { ClientOptions } from './request';

export interface Resource<T = never> {
path: string;
namespace?: BlizzardNamespaces;
params?: T;
}
export type ResourceResponse<T = unknown> = Promise<T>;

export type ResourceOptions<T> = Partial<ClientOptions> & T;
export type ResourceInterface<T = unknown, P = unknown> = (options: ResourceOptions<T>) => Resource<P>;

export type ProtectedResourceOptions<T> = Partial<ClientOptions> & { token: string } & T;
export type ProtectedResourceInterface<T = unknown, P = unknown> = (
options: ProtectedResourceOptions<T>,
) => Resource<P>;

0 comments on commit 00c0830

Please sign in to comment.