@codegenapps/frontend-sdk 1.0.1 → 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
@@ -14,17 +14,17 @@ This SDK is designed to be highly flexible. It dynamically fetches an API specif
14
14
  ## Installation
15
15
 
16
16
  ```bash
17
- npm install frontend-sdk # Replace 'frontend-sdk' with your actual package name on npm
17
+ npm install @codegenapps/frontend-sdk
18
18
  ```
19
19
 
20
20
  ## Quick Start
21
21
 
22
- Here's how to initialize the client and perform a query:
22
+ The following example demonstrates how to initialize the client and perform a query in a standard JavaScript environment.
23
23
 
24
24
  ```javascript
25
- import cga from 'frontend-sdk';
25
+ import cga from '@codegenapps/frontend-sdk';
26
26
 
27
- // 1. Initialize the client
27
+ // 1. Initialize the client (ideally once when your application starts)
28
28
  async function initialize() {
29
29
  await cga.init({
30
30
  // The base URL of your API
@@ -63,6 +63,101 @@ async function fetchDocuments() {
63
63
  initialize().then(fetchDocuments);
64
64
  ```
65
65
 
66
+ ## Usage with Frameworks
67
+
68
+ This SDK is framework-agnostic. The Quick Start example uses standard JavaScript (`async/await`) that works in any modern environment. Here’s how you might integrate it into popular frameworks.
69
+
70
+ ### React Example
71
+
72
+ In a React component, you can use the `useEffect` hook to fetch data when the component mounts.
73
+
74
+ ```jsx
75
+ import React, { useState, useEffect } from 'react';
76
+ import cga from '@codegenapps/frontend-sdk';
77
+
78
+ // Initialize the SDK once in your app's entry point (e.g., index.js)
79
+ // await cga.init({ ... });
80
+
81
+ function DocumentsList() {
82
+ const [documents, setDocuments] = useState([]);
83
+ const [error, setError] = useState(null);
84
+ const [isLoading, setIsLoading] = useState(true);
85
+
86
+ useEffect(() => {
87
+ async function getDocuments() {
88
+ const { data, error } = await cga
89
+ .from('documents')
90
+ .select('id, title')
91
+ .eq('owner_id', 1)
92
+ .run();
93
+
94
+ if (error) {
95
+ setError(error);
96
+ } else {
97
+ setDocuments(data);
98
+ }
99
+ setIsLoading(false);
100
+ }
101
+
102
+ getDocuments();
103
+ }, []); // The empty dependency array ensures this runs once on mount
104
+
105
+ if (isLoading) return <div>Loading...</div>;
106
+ if (error) return <div>Error: {error.message}</div>;
107
+
108
+ return (
109
+ <ul>
110
+ {documents.map(doc => (
111
+ <li key={doc.id}>{doc.title}</li>
112
+ ))}
113
+ </ul>
114
+ );
115
+ }
116
+ ```
117
+
118
+ ### Vue.js Example
119
+
120
+ In a Vue component (using Composition API), you can use the `onMounted` hook.
121
+
122
+ ```vue
123
+ <script setup>
124
+ import { ref, onMounted } from 'vue';
125
+ import cga from '@codegenapps/frontend-sdk';
126
+
127
+ // Initialize the SDK once in your app's entry point (e.g., main.js)
128
+ // await cga.init({ ... });
129
+
130
+ const documents = ref([]);
131
+ const error = ref(null);
132
+ const isLoading = ref(true);
133
+
134
+ onMounted(async () => {
135
+ const { data, error: fetchError } = await cga
136
+ .from('documents')
137
+ .select('id, title')
138
+ .eq('owner_id', 1)
139
+ .run();
140
+
141
+ if (fetchError) {
142
+ error.value = fetchError;
143
+ } else {
144
+ documents.value = data;
145
+ }
146
+ isLoading.value = false;
147
+ });
148
+ </script>
149
+
150
+ <template>
151
+ <div v-if="isLoading">Loading...</div>
152
+ <div v-else-if="error">Error: {{ error.message }}</div>
153
+ <ul v-else>
154
+ <li v-for="doc in documents" :key="doc.id">
155
+ {{ doc.title }}
156
+ </li>
157
+ </ul>
158
+ </template>
159
+ ```
160
+
66
161
  ## API
67
162
 
68
163
  ### Initialization
@@ -117,4 +212,4 @@ Executes the query and returns a `Promise` that resolves to `{ data, error }`. *
117
212
 
118
213
  ## License
119
214
 
120
- MIT
215
+ MIT
@@ -54,11 +54,11 @@ export declare class CgaClient {
54
54
  get auth(): {
55
55
  /**
56
56
  * Logs in a user.
57
- * @param username The user's username.
57
+ * @param account The user's username.
58
58
  * @param password The user's password.
59
59
  * @param apiKey The API key required for login.
60
60
  */
61
- login(username: string, password: string, apiKey: string): Promise<{
61
+ login(account: string, password: string, apiKey: string): Promise<{
62
62
  data: any;
63
63
  error: null;
64
64
  } | {
package/dist/index.esm.js CHANGED
@@ -6366,15 +6366,15 @@ class CgaClient {
6366
6366
  return {
6367
6367
  /**
6368
6368
  * Logs in a user.
6369
- * @param username The user's username.
6369
+ * @param account The user's username.
6370
6370
  * @param password The user's password.
6371
6371
  * @param apiKey The API key required for login.
6372
6372
  */
6373
- login(username, password, apiKey) {
6373
+ login(account, password, apiKey) {
6374
6374
  return __awaiter(this, void 0, void 0, function* () {
6375
6375
  var _a;
6376
6376
  try {
6377
- const response = yield httpClient.post('/auth/login', { username, password }, { headers: { 'X-API-KEY': apiKey } });
6377
+ const response = yield httpClient.post('/auth/login', { account, password }, { headers: { 'X-API-KEY': apiKey } });
6378
6378
  return { data: response.data.data, error: null };
6379
6379
  }
6380
6380
  catch (error) {