@mybe/sdk 1.0.0 → 1.0.2

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 CHANGED
@@ -50,7 +50,9 @@ const sdk = new MybeSDK({
50
50
 
51
51
  The SDK automatically detects the environment:
52
52
  - **Development** (`NODE_ENV=development`): Uses `http://localhost:3001/api/v1`
53
- - **Production**: Uses `https://api.mybe.app/api/v1`
53
+ - **Production**: Uses `https://fizsdck7l0.execute-api.us-east-1.amazonaws.com/dev/api/v1`
54
+
55
+ > **Note:** The production endpoint uses AWS API Gateway REST API with API key validation and automatic usage tracking.
54
56
 
55
57
  ### Custom Base URL (Optional)
56
58
 
@@ -0,0 +1,34 @@
1
+ import { MybeSDKConfig, ContentType, ContentEntry, ContentFilterOptions, ContentListResponse } from './types.js';
2
+ export declare class MybeSDK {
3
+ private apiKey;
4
+ private baseUrl;
5
+ constructor(config: MybeSDKConfig);
6
+ /**
7
+ * Make HTTP request to API
8
+ */
9
+ private request;
10
+ /**
11
+ * Build query string from options
12
+ */
13
+ private buildQueryString;
14
+ /**
15
+ * Get all content models (content types) for a project
16
+ */
17
+ getContentModels(projectId: string): Promise<ContentType[]>;
18
+ /**
19
+ * Get a specific content model by ID
20
+ */
21
+ getContentModel(contentTypeId: string): Promise<ContentType>;
22
+ /**
23
+ * Get a single content entry by ID
24
+ */
25
+ getContent(contentId: string): Promise<ContentEntry>;
26
+ /**
27
+ * Get all content entries for a specific content type
28
+ */
29
+ getContentByType(contentTypeId: string, options?: ContentFilterOptions): Promise<ContentListResponse>;
30
+ /**
31
+ * Get all content entries for a project
32
+ */
33
+ getContentByProject(projectId: string, options?: ContentFilterOptions): Promise<ContentListResponse>;
34
+ }
package/dist/client.js ADDED
@@ -0,0 +1,129 @@
1
+ import { MybeSDKError, NotFoundError, UnauthorizedError, ValidationError, ServerError, ForbiddenError, } from './errors.js';
2
+ export class MybeSDK {
3
+ apiKey;
4
+ baseUrl;
5
+ constructor(config) {
6
+ if (!config.apiKey) {
7
+ throw new MybeSDKError('API key is required');
8
+ }
9
+ this.apiKey = config.apiKey;
10
+ if (config.baseUrl) {
11
+ this.baseUrl = config.baseUrl;
12
+ }
13
+ else {
14
+ const isDevelopment = typeof process !== 'undefined' &&
15
+ process.env.NODE_ENV === 'development';
16
+ // Use REST API endpoint for production (with API key validation and usage tracking)
17
+ this.baseUrl = isDevelopment
18
+ ? 'http://localhost:3001/api/v1'
19
+ : 'https://fizsdck7l0.execute-api.us-east-1.amazonaws.com/dev/api/v1';
20
+ }
21
+ }
22
+ /**
23
+ * Make HTTP request to API
24
+ */
25
+ async request(endpoint, options = {}) {
26
+ const url = `${this.baseUrl}${endpoint}`;
27
+ const headers = {
28
+ 'Content-Type': 'application/json',
29
+ 'X-API-Key': this.apiKey,
30
+ ...options.headers,
31
+ };
32
+ try {
33
+ const response = await fetch(url, {
34
+ ...options,
35
+ headers,
36
+ });
37
+ const data = await response.json();
38
+ // Handle error responses
39
+ if (!response.ok) {
40
+ const errorMessage = data.message || 'An error occurred';
41
+ switch (response.status) {
42
+ case 400:
43
+ throw new ValidationError(errorMessage, data);
44
+ case 401:
45
+ throw new UnauthorizedError(errorMessage, data);
46
+ case 403:
47
+ throw new ForbiddenError(errorMessage, data);
48
+ case 404:
49
+ throw new NotFoundError(errorMessage, data);
50
+ case 500:
51
+ case 502:
52
+ case 503:
53
+ throw new ServerError(errorMessage, data);
54
+ default:
55
+ throw new MybeSDKError(errorMessage, response.status, data);
56
+ }
57
+ }
58
+ return data;
59
+ }
60
+ catch (error) {
61
+ // Re-throw SDK errors
62
+ if (error instanceof MybeSDKError) {
63
+ throw error;
64
+ }
65
+ // Handle network errors
66
+ if (error instanceof Error) {
67
+ throw new MybeSDKError(`Network error: ${error.message}`, undefined, error);
68
+ }
69
+ throw new MybeSDKError('An unknown error occurred');
70
+ }
71
+ }
72
+ /**
73
+ * Build query string from options
74
+ */
75
+ buildQueryString(options) {
76
+ if (!options)
77
+ return '';
78
+ const params = new URLSearchParams();
79
+ if (options.status) {
80
+ params.append('status', options.status);
81
+ }
82
+ if (options.locale) {
83
+ params.append('locale', options.locale);
84
+ }
85
+ if (options.limit) {
86
+ params.append('limit', options.limit.toString());
87
+ }
88
+ if (options.lastKey) {
89
+ params.append('lastKey', encodeURIComponent(options.lastKey));
90
+ }
91
+ const queryString = params.toString();
92
+ return queryString ? `?${queryString}` : '';
93
+ }
94
+ /**
95
+ * Get all content models (content types) for a project
96
+ */
97
+ async getContentModels(projectId) {
98
+ const response = await this.request(`/content-models/${projectId}`);
99
+ return response.data;
100
+ }
101
+ /**
102
+ * Get a specific content model by ID
103
+ */
104
+ async getContentModel(contentTypeId) {
105
+ const response = await this.request(`/content-model/${contentTypeId}`);
106
+ return response.data;
107
+ }
108
+ /**
109
+ * Get a single content entry by ID
110
+ */
111
+ async getContent(contentId) {
112
+ const response = await this.request(`/content-entry/${contentId}`);
113
+ return response.data;
114
+ }
115
+ /**
116
+ * Get all content entries for a specific content type
117
+ */
118
+ async getContentByType(contentTypeId, options) {
119
+ const queryString = this.buildQueryString(options);
120
+ return await this.request(`/type/${contentTypeId}${queryString}`);
121
+ }
122
+ /**
123
+ * Get all content entries for a project
124
+ */
125
+ async getContentByProject(projectId, options) {
126
+ const queryString = this.buildQueryString(options);
127
+ return await this.request(`/content-entry/project/${projectId}${queryString}`);
128
+ }
129
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Base SDK Error
3
+ */
4
+ export declare class MybeSDKError extends Error {
5
+ statusCode?: number;
6
+ response?: any;
7
+ constructor(message: string, statusCode?: number, response?: any);
8
+ }
9
+ /**
10
+ * Not Found Error (404)
11
+ */
12
+ export declare class NotFoundError extends MybeSDKError {
13
+ constructor(message?: string, response?: any);
14
+ }
15
+ /**
16
+ * Unauthorized Error (401)
17
+ */
18
+ export declare class UnauthorizedError extends MybeSDKError {
19
+ constructor(message?: string, response?: any);
20
+ }
21
+ /**
22
+ * Validation Error (400)
23
+ */
24
+ export declare class ValidationError extends MybeSDKError {
25
+ constructor(message?: string, response?: any);
26
+ }
27
+ /**
28
+ * Server Error (500)
29
+ */
30
+ export declare class ServerError extends MybeSDKError {
31
+ constructor(message?: string, response?: any);
32
+ }
33
+ /**
34
+ * Forbidden Error (403)
35
+ */
36
+ export declare class ForbiddenError extends MybeSDKError {
37
+ constructor(message?: string, response?: any);
38
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Base SDK Error
3
+ */
4
+ export class MybeSDKError extends Error {
5
+ statusCode;
6
+ response;
7
+ constructor(message, statusCode, response) {
8
+ super(message);
9
+ this.name = 'MybeSDKError';
10
+ this.statusCode = statusCode;
11
+ this.response = response;
12
+ Object.setPrototypeOf(this, MybeSDKError.prototype);
13
+ }
14
+ }
15
+ /**
16
+ * Not Found Error (404)
17
+ */
18
+ export class NotFoundError extends MybeSDKError {
19
+ constructor(message = 'Resource not found', response) {
20
+ super(message, 404, response);
21
+ this.name = 'NotFoundError';
22
+ Object.setPrototypeOf(this, NotFoundError.prototype);
23
+ }
24
+ }
25
+ /**
26
+ * Unauthorized Error (401)
27
+ */
28
+ export class UnauthorizedError extends MybeSDKError {
29
+ constructor(message = 'Unauthorized - Invalid API key', response) {
30
+ super(message, 401, response);
31
+ this.name = 'UnauthorizedError';
32
+ Object.setPrototypeOf(this, UnauthorizedError.prototype);
33
+ }
34
+ }
35
+ /**
36
+ * Validation Error (400)
37
+ */
38
+ export class ValidationError extends MybeSDKError {
39
+ constructor(message = 'Validation failed', response) {
40
+ super(message, 400, response);
41
+ this.name = 'ValidationError';
42
+ Object.setPrototypeOf(this, ValidationError.prototype);
43
+ }
44
+ }
45
+ /**
46
+ * Server Error (500)
47
+ */
48
+ export class ServerError extends MybeSDKError {
49
+ constructor(message = 'Internal server error', response) {
50
+ super(message, 500, response);
51
+ this.name = 'ServerError';
52
+ Object.setPrototypeOf(this, ServerError.prototype);
53
+ }
54
+ }
55
+ /**
56
+ * Forbidden Error (403)
57
+ */
58
+ export class ForbiddenError extends MybeSDKError {
59
+ constructor(message = 'Forbidden - Insufficient permissions', response) {
60
+ super(message, 403, response);
61
+ this.name = 'ForbiddenError';
62
+ Object.setPrototypeOf(this, ForbiddenError.prototype);
63
+ }
64
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Mybe CMS SDK
3
+ *
4
+ * A TypeScript SDK for fetching content from Mybe CMS.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { MybeSDK } from '@mybe/sdk';
9
+ *
10
+ * const sdk = new MybeSDK({
11
+ * apiKey: 'your-api-key'
12
+ * });
13
+ *
14
+ * // Fetch content
15
+ * const content = await sdk.getContent('content-id');
16
+ * const contentList = await sdk.getContentByType('content-type-id', {
17
+ * status: 'published',
18
+ * limit: 10
19
+ * });
20
+ * ```
21
+ */
22
+ export { MybeSDK } from './client.js';
23
+ export { MybeSDKConfig, ContentType, ContentEntry, ContentFilterOptions, PaginationOptions, PaginationResponse, APIResponse, ContentListResponse, } from './types.js';
24
+ export { MybeSDKError, NotFoundError, UnauthorizedError, ValidationError, ServerError, ForbiddenError, } from './errors.js';
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Mybe CMS SDK
3
+ *
4
+ * A TypeScript SDK for fetching content from Mybe CMS.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { MybeSDK } from '@mybe/sdk';
9
+ *
10
+ * const sdk = new MybeSDK({
11
+ * apiKey: 'your-api-key'
12
+ * });
13
+ *
14
+ * // Fetch content
15
+ * const content = await sdk.getContent('content-id');
16
+ * const contentList = await sdk.getContentByType('content-type-id', {
17
+ * status: 'published',
18
+ * limit: 10
19
+ * });
20
+ * ```
21
+ */
22
+ export { MybeSDK } from './client.js';
23
+ export { MybeSDKError, NotFoundError, UnauthorizedError, ValidationError, ServerError, ForbiddenError, } from './errors.js';
@@ -0,0 +1,73 @@
1
+ /**
2
+ * SDK Configuration
3
+ */
4
+ export interface MybeSDKConfig {
5
+ apiKey: string;
6
+ baseUrl?: string;
7
+ }
8
+ /**
9
+ * Content Type (Content Model)
10
+ */
11
+ export interface ContentType {
12
+ id: string;
13
+ project_id: string;
14
+ name: string;
15
+ slug: string;
16
+ description?: string;
17
+ created_at: string;
18
+ updated_at: string;
19
+ }
20
+ /**
21
+ * Content Entry
22
+ */
23
+ export interface ContentEntry {
24
+ id: string;
25
+ content_type_id: string;
26
+ project_id: string;
27
+ slug?: string;
28
+ status: 'draft' | 'published' | 'archived';
29
+ data: Record<string, any>;
30
+ locale?: string;
31
+ created_by: string;
32
+ updated_by?: string;
33
+ published_at?: string;
34
+ created_at: string;
35
+ updated_at: string;
36
+ }
37
+ /**
38
+ * Pagination Options
39
+ */
40
+ export interface PaginationOptions {
41
+ limit?: number;
42
+ lastKey?: string;
43
+ }
44
+ /**
45
+ * Content Filter Options
46
+ */
47
+ export interface ContentFilterOptions extends PaginationOptions {
48
+ status?: 'draft' | 'published' | 'archived';
49
+ locale?: string;
50
+ }
51
+ /**
52
+ * Pagination Response
53
+ */
54
+ export interface PaginationResponse {
55
+ lastEvaluatedKey?: Record<string, any>;
56
+ hasMore: boolean;
57
+ }
58
+ /**
59
+ * API Response Wrapper
60
+ */
61
+ export interface APIResponse<T> {
62
+ data: T;
63
+ message: string;
64
+ pagination?: PaginationResponse;
65
+ }
66
+ /**
67
+ * Content List Response
68
+ */
69
+ export interface ContentListResponse {
70
+ data: ContentEntry[];
71
+ pagination: PaginationResponse;
72
+ message: string;
73
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@mybe/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist/",
9
+ "README.md"
10
+ ],
7
11
  "exports": {
8
12
  ".": {
9
13
  "types": "./dist/index.d.ts",
@@ -15,11 +19,6 @@
15
19
  "dev": "tsc --watch",
16
20
  "typecheck": "tsc --noEmit",
17
21
  "test": "npm run build && npx tsx test.ts",
18
- "prepublishOnly": "npm run build",
19
- "prepack": "npm run build"
20
- },
21
- "dependencies": {},
22
- "devDependencies": {
23
- "typescript": "^5.9.2"
22
+ "prepublishOnly": "npm run build"
24
23
  }
25
24
  }