@chanomhub/sdk 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -0
- package/dist/__tests__/client.test.d.ts +2 -0
- package/dist/__tests__/client.test.d.ts.map +1 -0
- package/dist/__tests__/client.test.js +55 -0
- package/dist/__tests__/client.test.js.map +1 -0
- package/dist/__tests__/imageUrl.test.d.ts +2 -0
- package/dist/__tests__/imageUrl.test.d.ts.map +1 -0
- package/dist/__tests__/imageUrl.test.js +89 -0
- package/dist/__tests__/imageUrl.test.js.map +1 -0
- package/dist/__tests__/mocks/handlers.d.ts +2 -0
- package/dist/__tests__/mocks/handlers.d.ts.map +1 -0
- package/dist/__tests__/mocks/handlers.js +104 -0
- package/dist/__tests__/mocks/handlers.js.map +1 -0
- package/dist/__tests__/mocks/server.d.ts +2 -0
- package/dist/__tests__/mocks/server.d.ts.map +1 -0
- package/dist/__tests__/mocks/server.js +7 -0
- package/dist/__tests__/mocks/server.js.map +1 -0
- package/dist/__tests__/setup.d.ts +2 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +8 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +73 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -0
- package/dist/next.d.ts +30 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +84 -0
- package/dist/next.js.map +1 -0
- package/dist/repositories/articleRepository.d.ts +30 -0
- package/dist/repositories/articleRepository.d.ts.map +1 -0
- package/dist/repositories/articleRepository.js +265 -0
- package/dist/repositories/articleRepository.js.map +1 -0
- package/dist/repositories/index.d.ts +5 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +9 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/transforms/imageUrl.d.ts +17 -0
- package/dist/transforms/imageUrl.d.ts.map +1 -0
- package/dist/transforms/imageUrl.js +70 -0
- package/dist/transforms/imageUrl.js.map +1 -0
- package/dist/types/article.d.ts +87 -0
- package/dist/types/article.d.ts.map +1 -0
- package/dist/types/article.js +6 -0
- package/dist/types/article.js.map +1 -0
- package/dist/types/common.d.ts +67 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +6 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +16 -0
- package/dist/vitest.config.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Chanomhub SDK
|
|
2
|
+
|
|
3
|
+
A framework-agnostic TypeScript SDK for interacting with the Chanomhub API.
|
|
4
|
+
Works with Next.js, React Native, Node.js, and browser environments.
|
|
5
|
+
|
|
6
|
+
## Testing
|
|
7
|
+
|
|
8
|
+
Run the test suite with:
|
|
9
|
+
```bash
|
|
10
|
+
npm test
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @chanomhub/sdk
|
|
17
|
+
# or
|
|
18
|
+
yarn add @chanomhub/sdk
|
|
19
|
+
# or
|
|
20
|
+
pnpm add @chanomhub/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createChanomhubClient } from '@chanomhub/sdk';
|
|
29
|
+
|
|
30
|
+
// Public access
|
|
31
|
+
const sdk = createChanomhubClient();
|
|
32
|
+
const articles = await sdk.articles.getByTag('renpy');
|
|
33
|
+
|
|
34
|
+
// With authentication
|
|
35
|
+
const sdk = createChanomhubClient({ token: 'your-jwt-token' });
|
|
36
|
+
const article = await sdk.articles.getBySlug('my-article');
|
|
37
|
+
|
|
38
|
+
// With custom config
|
|
39
|
+
const sdk = createChanomhubClient({
|
|
40
|
+
apiUrl: 'https://api.chanomhub.online',
|
|
41
|
+
cdnUrl: 'https://cdn.chanomhub.com',
|
|
42
|
+
token: 'jwt-token',
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Next.js Usage
|
|
47
|
+
|
|
48
|
+
For Next.js (especially Server Components), use the helper from `chanomhub-sdk/next` to automatically handle authentication cookies.
|
|
49
|
+
|
|
50
|
+
First, ensure you have `next` installed in your project.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// app/page.tsx (Server Component)
|
|
54
|
+
import { createServerClient } from 'chanomhub-sdk/next';
|
|
55
|
+
|
|
56
|
+
export default async function Page() {
|
|
57
|
+
const sdk = await createServerClient(); // Automatically reads 'token' from cookies
|
|
58
|
+
const articles = await sdk.articles.getAll();
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div>
|
|
62
|
+
{articles.map(article => (
|
|
63
|
+
<h2 key={article.id}>{article.title}</h2>
|
|
64
|
+
))}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Features
|
|
71
|
+
|
|
72
|
+
- **Typed:** Fully written in TypeScript with complete type definitions.
|
|
73
|
+
- **Modular:** Framework-agnostic core with specific helpers for Next.js.
|
|
74
|
+
- **Configurable:** Easy to override API endpoints and cache settings.
|
|
75
|
+
- **Auth-aware:** Helpers to manage JWT tokens automatically.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
ISC
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../__tests__/client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const CDN_URL = config_1.DEFAULT_CONFIG.cdnUrl;
|
|
7
|
+
(0, vitest_1.describe)('Chanomhub SDK Integration Tests (MSW)', () => {
|
|
8
|
+
(0, vitest_1.it)('should fetch and transform articles correctly', async () => {
|
|
9
|
+
const client = (0, index_1.createChanomhubClient)();
|
|
10
|
+
const articles = await client.articles.getAll();
|
|
11
|
+
(0, vitest_1.expect)(articles).toHaveLength(2);
|
|
12
|
+
// Check transformation locally (filename only -> full URL)
|
|
13
|
+
(0, vitest_1.expect)(articles[0].mainImage).toBe(`${CDN_URL}/article1.jpg`);
|
|
14
|
+
// Check no double transformation (full URL stays full URL)
|
|
15
|
+
(0, vitest_1.expect)(articles[1].mainImage).toBe('https://external.com/image.jpg');
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.it)('should fetch single article by slug and transform nested fields', async () => {
|
|
18
|
+
const client = (0, index_1.createChanomhubClient)();
|
|
19
|
+
const article = await client.articles.getBySlug('test-article-1');
|
|
20
|
+
(0, vitest_1.expect)(article).not.toBeNull();
|
|
21
|
+
(0, vitest_1.expect)(article.slug).toBe('test-article-1');
|
|
22
|
+
// Check flat field
|
|
23
|
+
(0, vitest_1.expect)(article.mainImage).toBe(`${CDN_URL}/article1.jpg`);
|
|
24
|
+
// Check nested author image
|
|
25
|
+
(0, vitest_1.expect)(article.author.image).toBe(`${CDN_URL}/john.jpg`);
|
|
26
|
+
// Check array of images
|
|
27
|
+
(0, vitest_1.expect)(article.images[0].url).toBe(`${CDN_URL}/img1.jpg`);
|
|
28
|
+
(0, vitest_1.expect)(article.images[1].url).toBe(`${CDN_URL}/img2.jpg`);
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)('should return null when article not found', async () => {
|
|
31
|
+
const client = (0, index_1.createChanomhubClient)();
|
|
32
|
+
const article = await client.articles.getBySlug('not-found');
|
|
33
|
+
(0, vitest_1.expect)(article).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.it)('should handle server errors (500)', async () => {
|
|
36
|
+
const client = (0, index_1.createChanomhubClient)();
|
|
37
|
+
// We use the raw graphql client here to target the specific error handler
|
|
38
|
+
const result = await client.graphql('query ServerErrorQuery { test }', {}, {
|
|
39
|
+
operationName: 'ServerErrorQuery'
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.expect)(result.data).toBeNull();
|
|
42
|
+
// The SDK converts non-ok status to an error message
|
|
43
|
+
(0, vitest_1.expect)(result.errors[0].message).toContain('HTTP 500');
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('should handle GraphQL errors', async () => {
|
|
46
|
+
const client = (0, index_1.createChanomhubClient)();
|
|
47
|
+
const result = await client.graphql('query GraphQLErrorQuery { test }', {}, {
|
|
48
|
+
operationName: 'GraphQLErrorQuery'
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.expect)(result.data).toBeNull();
|
|
51
|
+
(0, vitest_1.expect)(result.errors).toHaveLength(1);
|
|
52
|
+
(0, vitest_1.expect)(result.errors[0].message).toBe('Something went wrong in GraphQL');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=client.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.test.js","sourceRoot":"","sources":["../../__tests__/client.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAC9C,oCAAiD;AACjD,sCAA2C;AAE3C,MAAM,OAAO,GAAG,uBAAc,CAAC,MAAM,CAAC;AAEtC,IAAA,iBAAQ,EAAC,uCAAuC,EAAE,GAAG,EAAE;IAE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,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC/B,IAAA,eAAM,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACtC,IAAA,eAAM,EAAC,MAAM,CAAC,MAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageUrl.test.d.ts","sourceRoot":"","sources":["../../__tests__/imageUrl.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const imageUrl_1 = require("../transforms/imageUrl");
|
|
5
|
+
const CDN_URL = 'https://cdn.chanomhub.com';
|
|
6
|
+
(0, vitest_1.describe)('resolveImageUrl', () => {
|
|
7
|
+
(0, vitest_1.it)('should return null for null input', () => {
|
|
8
|
+
(0, vitest_1.expect)((0, imageUrl_1.resolveImageUrl)(null, CDN_URL)).toBeNull();
|
|
9
|
+
});
|
|
10
|
+
(0, vitest_1.it)('should return null for undefined input', () => {
|
|
11
|
+
(0, vitest_1.expect)((0, imageUrl_1.resolveImageUrl)(undefined, CDN_URL)).toBeNull();
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.it)('should return full URL as-is for http URLs', () => {
|
|
14
|
+
const url = 'http://example.com/image.jpg';
|
|
15
|
+
(0, vitest_1.expect)((0, imageUrl_1.resolveImageUrl)(url, CDN_URL)).toBe(url);
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.it)('should return full URL as-is for https URLs', () => {
|
|
18
|
+
const url = 'https://example.com/image.jpg';
|
|
19
|
+
(0, vitest_1.expect)((0, imageUrl_1.resolveImageUrl)(url, CDN_URL)).toBe(url);
|
|
20
|
+
});
|
|
21
|
+
(0, vitest_1.it)('should prepend CDN URL for filename only', () => {
|
|
22
|
+
(0, vitest_1.expect)((0, imageUrl_1.resolveImageUrl)('abc.jpg', CDN_URL)).toBe('https://cdn.chanomhub.com/abc.jpg');
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)('should handle filenames with paths', () => {
|
|
25
|
+
(0, vitest_1.expect)((0, imageUrl_1.resolveImageUrl)('uploads/abc.jpg', CDN_URL)).toBe('https://cdn.chanomhub.com/uploads/abc.jpg');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.describe)('transformImageUrlsDeep', () => {
|
|
29
|
+
(0, vitest_1.it)('should return null/undefined as-is', () => {
|
|
30
|
+
(0, vitest_1.expect)((0, imageUrl_1.transformImageUrlsDeep)(null, CDN_URL)).toBeNull();
|
|
31
|
+
(0, vitest_1.expect)((0, imageUrl_1.transformImageUrlsDeep)(undefined, CDN_URL)).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)('should transform known image fields', () => {
|
|
34
|
+
const data = {
|
|
35
|
+
mainImage: 'main.jpg',
|
|
36
|
+
coverImage: 'cover.jpg',
|
|
37
|
+
backgroundImage: 'bg.jpg',
|
|
38
|
+
image: 'profile.jpg',
|
|
39
|
+
title: 'Test Article',
|
|
40
|
+
};
|
|
41
|
+
const result = (0, imageUrl_1.transformImageUrlsDeep)(data, CDN_URL);
|
|
42
|
+
(0, vitest_1.expect)(result.mainImage).toBe('https://cdn.chanomhub.com/main.jpg');
|
|
43
|
+
(0, vitest_1.expect)(result.coverImage).toBe('https://cdn.chanomhub.com/cover.jpg');
|
|
44
|
+
(0, vitest_1.expect)(result.backgroundImage).toBe('https://cdn.chanomhub.com/bg.jpg');
|
|
45
|
+
(0, vitest_1.expect)(result.image).toBe('https://cdn.chanomhub.com/profile.jpg');
|
|
46
|
+
(0, vitest_1.expect)(result.title).toBe('Test Article'); // Non-image field unchanged
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.it)('should not transform already full URLs', () => {
|
|
49
|
+
const data = {
|
|
50
|
+
mainImage: 'https://existing.com/image.jpg',
|
|
51
|
+
};
|
|
52
|
+
const result = (0, imageUrl_1.transformImageUrlsDeep)(data, CDN_URL);
|
|
53
|
+
(0, vitest_1.expect)(result.mainImage).toBe('https://existing.com/image.jpg');
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.it)('should transform images array with url property', () => {
|
|
56
|
+
const data = {
|
|
57
|
+
images: [
|
|
58
|
+
{ url: 'image1.jpg' },
|
|
59
|
+
{ url: 'image2.jpg' },
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const result = (0, imageUrl_1.transformImageUrlsDeep)(data, CDN_URL);
|
|
63
|
+
(0, vitest_1.expect)(result.images[0].url).toBe('https://cdn.chanomhub.com/image1.jpg');
|
|
64
|
+
(0, vitest_1.expect)(result.images[1].url).toBe('https://cdn.chanomhub.com/image2.jpg');
|
|
65
|
+
});
|
|
66
|
+
(0, vitest_1.it)('should recursively transform nested objects', () => {
|
|
67
|
+
const data = {
|
|
68
|
+
article: {
|
|
69
|
+
mainImage: 'article.jpg',
|
|
70
|
+
author: {
|
|
71
|
+
image: 'author.jpg',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const result = (0, imageUrl_1.transformImageUrlsDeep)(data, CDN_URL);
|
|
76
|
+
(0, vitest_1.expect)(result.article.mainImage).toBe('https://cdn.chanomhub.com/article.jpg');
|
|
77
|
+
(0, vitest_1.expect)(result.article.author.image).toBe('https://cdn.chanomhub.com/author.jpg');
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.it)('should handle arrays at root level', () => {
|
|
80
|
+
const data = [
|
|
81
|
+
{ mainImage: 'img1.jpg' },
|
|
82
|
+
{ mainImage: 'img2.jpg' },
|
|
83
|
+
];
|
|
84
|
+
const result = (0, imageUrl_1.transformImageUrlsDeep)(data, CDN_URL);
|
|
85
|
+
(0, vitest_1.expect)(result[0].mainImage).toBe('https://cdn.chanomhub.com/img1.jpg');
|
|
86
|
+
(0, vitest_1.expect)(result[1].mainImage).toBe('https://cdn.chanomhub.com/img2.jpg');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=imageUrl.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageUrl.test.js","sourceRoot":"","sources":["../../__tests__/imageUrl.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAC9C,qDAAiF;AAEjF,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAE5C,IAAA,iBAAQ,EAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,IAAA,WAAE,EAAC,mCAAmC,EAAE,GAAG,EAAE;QACzC,IAAA,eAAM,EAAC,IAAA,0BAAe,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,wCAAwC,EAAE,GAAG,EAAE;QAC9C,IAAA,eAAM,EAAC,IAAA,0BAAe,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,4CAA4C,EAAE,GAAG,EAAE;QAClD,MAAM,GAAG,GAAG,8BAA8B,CAAC;QAC3C,IAAA,eAAM,EAAC,IAAA,0BAAe,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,6CAA6C,EAAE,GAAG,EAAE;QACnD,MAAM,GAAG,GAAG,+BAA+B,CAAC;QAC5C,IAAA,eAAM,EAAC,IAAA,0BAAe,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,IA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;SACJ,CAAC;QAEF,MAAM,MAAM,GAAG,IAAA,iCAAsB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAErD,IAAA,eAAM,EAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QAC/E,IAAA,eAAM,EAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,oCAAoC,EAAE,GAAG,EAAE;QAC1C,MAAM,IAAI,GAAG;YACT,EAAE,SAAS,EAAE,UAAU,EAAE;YACzB,EAAE,SAAS,EAAE,UAAU,EAAE;SAC5B,CAAC;QAEF,MAAM,MAAM,GAAG,IAAA,iCAAsB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAErD,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;QACvE,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../__tests__/mocks/handlers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,gCAuGpB,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handlers = void 0;
|
|
4
|
+
const msw_1 = require("msw");
|
|
5
|
+
exports.handlers = [
|
|
6
|
+
// Happy path: Get Articles
|
|
7
|
+
msw_1.graphql.query('GetArticles', () => {
|
|
8
|
+
return msw_1.HttpResponse.json({
|
|
9
|
+
data: {
|
|
10
|
+
articles: [
|
|
11
|
+
{
|
|
12
|
+
id: 1,
|
|
13
|
+
title: 'Test Article 1',
|
|
14
|
+
slug: 'test-article-1',
|
|
15
|
+
mainImage: 'article1.jpg',
|
|
16
|
+
status: 'PUBLISHED',
|
|
17
|
+
engine: { id: 'ng1', name: 'RenPy' },
|
|
18
|
+
author: { name: 'Author 1', image: 'auth1.jpg' },
|
|
19
|
+
creators: [],
|
|
20
|
+
tags: [],
|
|
21
|
+
platforms: [],
|
|
22
|
+
categories: [],
|
|
23
|
+
images: []
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 2,
|
|
27
|
+
title: 'Test Article 2',
|
|
28
|
+
slug: 'test-article-2',
|
|
29
|
+
mainImage: 'https://external.com/image.jpg',
|
|
30
|
+
status: 'PUBLISHED',
|
|
31
|
+
engine: { id: 'ng2', name: 'Unity' },
|
|
32
|
+
author: { name: 'Author 2', image: 'auth2.jpg' },
|
|
33
|
+
creators: [],
|
|
34
|
+
tags: [],
|
|
35
|
+
platforms: [],
|
|
36
|
+
categories: [],
|
|
37
|
+
images: []
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}),
|
|
43
|
+
// Happy path: Get Article By Slug
|
|
44
|
+
msw_1.graphql.query('GetArticleBySlug', ({ variables }) => {
|
|
45
|
+
const { slug } = variables;
|
|
46
|
+
if (slug === 'not-found') {
|
|
47
|
+
return msw_1.HttpResponse.json({
|
|
48
|
+
data: { article: null },
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return msw_1.HttpResponse.json({
|
|
52
|
+
data: {
|
|
53
|
+
article: {
|
|
54
|
+
id: 1,
|
|
55
|
+
title: 'Test Article 1',
|
|
56
|
+
slug: slug,
|
|
57
|
+
description: 'A test article',
|
|
58
|
+
body: 'This is the body content',
|
|
59
|
+
ver: '1.0',
|
|
60
|
+
createdAt: '2023-01-01',
|
|
61
|
+
updatedAt: '2023-01-02',
|
|
62
|
+
status: 'PUBLISHED',
|
|
63
|
+
engine: { id: 'ng1', name: 'RenPy' },
|
|
64
|
+
mainImage: 'article1.jpg',
|
|
65
|
+
backgroundImage: 'bg.jpg',
|
|
66
|
+
coverImage: 'cover.jpg',
|
|
67
|
+
favorited: false,
|
|
68
|
+
favoritesCount: 10,
|
|
69
|
+
sequentialCode: '001',
|
|
70
|
+
author: {
|
|
71
|
+
name: 'John Doe',
|
|
72
|
+
bio: 'Bio',
|
|
73
|
+
image: 'john.jpg',
|
|
74
|
+
backgroundImage: 'auth_bg.jpg',
|
|
75
|
+
following: false,
|
|
76
|
+
socialMediaLinks: []
|
|
77
|
+
},
|
|
78
|
+
images: [
|
|
79
|
+
{ id: 'img1', url: 'img1.jpg' },
|
|
80
|
+
{ id: 'img2', url: 'img2.jpg' }
|
|
81
|
+
],
|
|
82
|
+
creators: [],
|
|
83
|
+
tags: [],
|
|
84
|
+
platforms: [],
|
|
85
|
+
categories: [],
|
|
86
|
+
mods: [],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}),
|
|
91
|
+
// Error path: Internal Server Error simulation
|
|
92
|
+
msw_1.graphql.query('ServerErrorQuery', () => {
|
|
93
|
+
return new msw_1.HttpResponse(null, { status: 500 });
|
|
94
|
+
}),
|
|
95
|
+
// Error path: GraphQL Error simulation
|
|
96
|
+
msw_1.graphql.query('GraphQLErrorQuery', () => {
|
|
97
|
+
return msw_1.HttpResponse.json({
|
|
98
|
+
errors: [
|
|
99
|
+
{ message: 'Something went wrong in GraphQL' }
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
}),
|
|
103
|
+
];
|
|
104
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../__tests__/mocks/handlers.ts"],"names":[],"mappings":";;;AAAA,6BAAkD;AAErC,QAAA,QAAQ,GAAG;IAC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E,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC;IAEF,uCAAuC;IACvC,aAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACpC,OAAO,kBAAY,CAAC,IAAI,CAAC;YACrB,MAAM,EAAE;gBACJ,EAAE,OAAO,EAAE,iCAAiC,EAAE;aACjD;SACJ,CAAC,CAAC;IACP,CAAC,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../__tests__/mocks/server.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,mCAA2B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.server = void 0;
|
|
4
|
+
const node_1 = require("msw/node");
|
|
5
|
+
const handlers_1 = require("./handlers");
|
|
6
|
+
exports.server = (0, node_1.setupServer)(...handlers_1.handlers);
|
|
7
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../__tests__/mocks/server.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AACvC,yCAAsC;AAEzB,QAAA,MAAM,GAAG,IAAA,kBAAW,EAAC,GAAG,mBAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../__tests__/setup.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const server_1 = require("./mocks/server");
|
|
5
|
+
(0, vitest_1.beforeAll)(() => server_1.server.listen());
|
|
6
|
+
(0, vitest_1.afterEach)(() => server_1.server.resetHandlers());
|
|
7
|
+
(0, vitest_1.afterAll)(() => server_1.server.close());
|
|
8
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../__tests__/setup.ts"],"names":[],"mappings":";;AAAA,mCAAwD;AACxD,2CAAwC;AAExC,IAAA,kBAAS,EAAC,GAAG,EAAE,CAAC,eAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AACjC,IAAA,kBAAS,EAAC,GAAG,EAAE,CAAC,eAAM,CAAC,aAAa,EAAE,CAAC,CAAC;AACxC,IAAA,iBAAQ,EAAC,GAAG,EAAE,CAAC,eAAM,CAAC,KAAK,EAAE,CAAC,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chanomhub SDK - GraphQL Client
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic GraphQL client using standard fetch API.
|
|
5
|
+
* Works with any JavaScript runtime that supports fetch.
|
|
6
|
+
*/
|
|
7
|
+
import type { ChanomhubConfig } from './config';
|
|
8
|
+
import type { GraphQLResponse } from './types/common';
|
|
9
|
+
export interface FetchOptions {
|
|
10
|
+
/** GraphQL operation name */
|
|
11
|
+
operationName?: string;
|
|
12
|
+
/** Cache duration in seconds (0 = no cache) */
|
|
13
|
+
cacheSeconds?: number;
|
|
14
|
+
/** Skip cache entirely */
|
|
15
|
+
noCache?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a GraphQL fetcher function with automatic image URL transformation
|
|
19
|
+
*
|
|
20
|
+
* @param config - SDK configuration
|
|
21
|
+
* @returns GraphQL fetch function
|
|
22
|
+
*/
|
|
23
|
+
export declare function createGraphQLClient(config: ChanomhubConfig): <T>(query: string, variables?: Record<string, unknown>, options?: FetchOptions) => Promise<GraphQLResponse<T>>;
|
|
24
|
+
export type GraphQLFetcher = ReturnType<typeof createGraphQLClient>;
|
|
25
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,MAAM,WAAW,YAAY;IACzB,6BAA6B;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,IACpB,CAAC,EAChC,OAAO,MAAM,EACb,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACvC,UAAS,YAAiB,KAC3B,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CA8DjC;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Chanomhub SDK - GraphQL Client
|
|
4
|
+
*
|
|
5
|
+
* Framework-agnostic GraphQL client using standard fetch API.
|
|
6
|
+
* Works with any JavaScript runtime that supports fetch.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createGraphQLClient = createGraphQLClient;
|
|
10
|
+
const imageUrl_1 = require("./transforms/imageUrl");
|
|
11
|
+
/**
|
|
12
|
+
* Creates a GraphQL fetcher function with automatic image URL transformation
|
|
13
|
+
*
|
|
14
|
+
* @param config - SDK configuration
|
|
15
|
+
* @returns GraphQL fetch function
|
|
16
|
+
*/
|
|
17
|
+
function createGraphQLClient(config) {
|
|
18
|
+
return async function graphqlFetch(query, variables = {}, options = {}) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const headers = {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
'Accept': 'application/json',
|
|
23
|
+
};
|
|
24
|
+
if (config.token) {
|
|
25
|
+
headers['Authorization'] = `Bearer ${config.token}`;
|
|
26
|
+
}
|
|
27
|
+
// Build fetch options - framework agnostic
|
|
28
|
+
const fetchOptions = {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers,
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
query,
|
|
33
|
+
variables,
|
|
34
|
+
...(options.operationName && { operationName: options.operationName }),
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
// Handle caching - use standard Cache-Control header approach
|
|
38
|
+
// Note: Next.js and some other frameworks may extend RequestInit with 'next' property
|
|
39
|
+
// We use a type-safe approach that works everywhere
|
|
40
|
+
const useCache = !options.noCache && !config.token;
|
|
41
|
+
const cacheSeconds = (_b = (_a = options.cacheSeconds) !== null && _a !== void 0 ? _a : config.defaultCacheSeconds) !== null && _b !== void 0 ? _b : 3600;
|
|
42
|
+
if (!useCache || cacheSeconds === 0) {
|
|
43
|
+
fetchOptions.cache = 'no-store';
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const res = await fetch(`${config.apiUrl}/api/graphql`, fetchOptions);
|
|
47
|
+
if (!res.ok) {
|
|
48
|
+
const errorText = await res.text();
|
|
49
|
+
console.error('GraphQL fetch error:', res.status, errorText);
|
|
50
|
+
return {
|
|
51
|
+
data: null,
|
|
52
|
+
errors: [{ message: `HTTP ${res.status}: ${res.statusText}` }],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const json = await res.json();
|
|
56
|
+
if (json.errors) {
|
|
57
|
+
console.error('GraphQL errors:', json.errors);
|
|
58
|
+
return { data: null, errors: json.errors };
|
|
59
|
+
}
|
|
60
|
+
// Auto-transform all image URLs in the response
|
|
61
|
+
const transformedData = (0, imageUrl_1.transformImageUrlsDeep)(json.data, config.cdnUrl);
|
|
62
|
+
return { data: transformedData };
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('GraphQL fetch exception:', error);
|
|
66
|
+
return {
|
|
67
|
+
data: null,
|
|
68
|
+
errors: [{ message: error instanceof Error ? error.message : 'Unknown error' }],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAqBH,kDAmEC;AApFD,oDAA+D;AAW/D;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,MAAuB;IACvD,OAAO,KAAK,UAAU,YAAY,CAC9B,KAAa,EACb,YAAqC,EAAE,EACvC,UAAwB,EAAE;;QAE1B,MAAM,OAAO,GAA2B;YACpC,cAAc,EAAE,kBAAkB;YAClC,QAAQ,EAAE,kBAAkB;SAC/B,CAAC;QAEF,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,MAAM,CAAC,KAAK,EAAE,CAAC;QACxD,CAAC;QAED,2CAA2C;QAC3C,MAAM,YAAY,GAAgB;YAC9B,MAAM,EAAE,MAAM;YACd,OAAO;YACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACjB,KAAK;gBACL,SAAS;gBACT,GAAG,CAAC,OAAO,CAAC,aAAa,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC;aACzE,CAAC;SACL,CAAC;QAEF,8DAA8D;QAC9D,sFAAsF;QACtF,oDAAoD;QACpD,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACnD,MAAM,YAAY,GAAG,MA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IAAI,EAAE,IAAI;gBACV,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;aAClF,CAAC;QACN,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chanomhub SDK Configuration
|
|
3
|
+
*/
|
|
4
|
+
export interface ChanomhubConfig {
|
|
5
|
+
/** API base URL */
|
|
6
|
+
apiUrl: string;
|
|
7
|
+
/** CDN base URL for images */
|
|
8
|
+
cdnUrl: string;
|
|
9
|
+
/** Authentication token (optional) */
|
|
10
|
+
token?: string;
|
|
11
|
+
/** Default cache duration in seconds (0 = no cache) */
|
|
12
|
+
defaultCacheSeconds?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_CONFIG: ChanomhubConfig;
|
|
15
|
+
/** Article status enum */
|
|
16
|
+
export type ArticleStatus = 'DRAFT' | 'PENDING_REVIEW' | 'PUBLISHED' | 'ARCHIVED' | 'NOT_APPROVED' | 'NEEDS_REVISION';
|
|
17
|
+
/** Game engine enum */
|
|
18
|
+
export type GameEngine = 'RENPY' | 'RPGM' | 'UNITY' | 'UNREAL' | 'GODOT' | 'TyranoBuilder' | 'WOLFRPG' | 'KIRIKIRI' | 'FLASH' | 'BakinPlayer';
|
|
19
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC5B,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,eAAO,MAAM,cAAc,EAAE,eAI5B,CAAC;AAEF,0BAA0B;AAC1B,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,gBAAgB,GAAG,WAAW,GAAG,UAAU,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAEtH,uBAAuB;AACvB,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,eAAe,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,aAAa,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Chanomhub SDK Configuration
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_CONFIG = void 0;
|
|
7
|
+
exports.DEFAULT_CONFIG = {
|
|
8
|
+
apiUrl: 'https://api.chanomhub.online',
|
|
9
|
+
cdnUrl: 'https://cdn.chanomhub.com',
|
|
10
|
+
defaultCacheSeconds: 3600,
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAaU,QAAA,cAAc,GAAoB;IAC3C,MAAM,EAAE,8BAA8B;IACtC,MAAM,EAAE,2BAA2B;IACnC,mBAAmB,EAAE,IAAI;CAC5B,CAAC"}
|