@oxy-hq/sdk 0.1.5 → 0.1.6
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 +52 -31
- package/dist/index.cjs +80 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +80 -49
- package/dist/index.mjs.map +1 -1
- package/dist/{postMessage-CufWf9ji.cjs → postMessage-B1J0jDRN.cjs} +15 -11
- package/dist/postMessage-B1J0jDRN.cjs.map +1 -0
- package/dist/{postMessage-CVS3MsL5.cjs → postMessage-BSNS3ccd.cjs} +1 -1
- package/dist/{postMessage-DLGITn0e.mjs → postMessage-BxdgtX8j.mjs} +15 -11
- package/dist/postMessage-BxdgtX8j.mjs.map +1 -0
- package/dist/{postMessage-DwfY0HM5.mjs → postMessage-D5wWgwcO.mjs} +1 -1
- package/package.json +2 -2
- package/dist/postMessage-CufWf9ji.cjs.map +0 -1
- package/dist/postMessage-DLGITn0e.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -33,38 +33,42 @@ npm install @duckdb/duckdb-wasm
|
|
|
33
33
|
Perfect for embedding dashboards in iframes (e.g., v0.dev, sandboxed environments):
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
|
-
import { OxyClient } from
|
|
36
|
+
import { OxyClient } from "@oxy/sdk";
|
|
37
37
|
|
|
38
38
|
// SDK automatically requests API key from parent window
|
|
39
39
|
const client = await OxyClient.create({
|
|
40
|
-
parentOrigin:
|
|
41
|
-
projectId:
|
|
42
|
-
baseUrl:
|
|
40
|
+
parentOrigin: "https://app.example.com", // Parent window origin
|
|
41
|
+
projectId: "your-project-uuid",
|
|
42
|
+
baseUrl: "https://api.oxy.tech",
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
// Use the client
|
|
46
46
|
const apps = await client.listApps();
|
|
47
|
-
console.log(
|
|
47
|
+
console.log("Available apps:", apps);
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
**Parent window setup** (one-time):
|
|
51
|
+
|
|
51
52
|
```typescript
|
|
52
53
|
// In parent window that hosts the iframe
|
|
53
|
-
window.addEventListener(
|
|
54
|
-
if (event.data.type !==
|
|
54
|
+
window.addEventListener("message", (event) => {
|
|
55
|
+
if (event.data.type !== "OXY_AUTH_REQUEST") return;
|
|
55
56
|
|
|
56
57
|
// Validate iframe origin
|
|
57
|
-
if (event.origin !==
|
|
58
|
+
if (event.origin !== "https://your-iframe-app.com") return;
|
|
58
59
|
|
|
59
60
|
// Send user's API key to iframe
|
|
60
|
-
event.source.postMessage(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
event.source.postMessage(
|
|
62
|
+
{
|
|
63
|
+
type: "OXY_AUTH_RESPONSE",
|
|
64
|
+
version: "1.0",
|
|
65
|
+
requestId: event.data.requestId,
|
|
66
|
+
apiKey: getUserApiKey(), // Your auth logic
|
|
67
|
+
projectId: "your-project-uuid",
|
|
68
|
+
baseUrl: "https://api.oxy.tech",
|
|
69
|
+
},
|
|
70
|
+
event.origin,
|
|
71
|
+
);
|
|
68
72
|
});
|
|
69
73
|
```
|
|
70
74
|
|
|
@@ -82,7 +86,7 @@ export OXY_BRANCH="main" # optional
|
|
|
82
86
|
Basic usage:
|
|
83
87
|
|
|
84
88
|
```typescript
|
|
85
|
-
import { OxyClient, createConfig } from
|
|
89
|
+
import { OxyClient, createConfig } from "@oxy/sdk";
|
|
86
90
|
|
|
87
91
|
// Create configuration from environment variables
|
|
88
92
|
const config = createConfig();
|
|
@@ -92,16 +96,16 @@ const client = new OxyClient(config);
|
|
|
92
96
|
|
|
93
97
|
// List all apps
|
|
94
98
|
const apps = await client.listApps();
|
|
95
|
-
console.log(
|
|
99
|
+
console.log("Available apps:", apps);
|
|
96
100
|
|
|
97
101
|
// Get app data
|
|
98
|
-
const data = await client.getAppData(
|
|
102
|
+
const data = await client.getAppData("dashboard.app.yml");
|
|
99
103
|
if (!data.error) {
|
|
100
|
-
console.log(
|
|
104
|
+
console.log("App data:", data.data);
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
// Fetch a file (e.g., chart image)
|
|
104
|
-
const blob = await client.getFile(
|
|
108
|
+
const blob = await client.getFile("charts/sales-chart.png");
|
|
105
109
|
const url = URL.createObjectURL(blob);
|
|
106
110
|
// Use the URL in an <img> tag
|
|
107
111
|
```
|
|
@@ -109,19 +113,19 @@ const url = URL.createObjectURL(blob);
|
|
|
109
113
|
### Reading Parquet Files
|
|
110
114
|
|
|
111
115
|
```typescript
|
|
112
|
-
import { OxyClient, createConfig, readParquet, ParquetReader } from
|
|
116
|
+
import { OxyClient, createConfig, readParquet, ParquetReader } from "@oxy/sdk";
|
|
113
117
|
|
|
114
118
|
const config = createConfig();
|
|
115
119
|
const client = new OxyClient(config);
|
|
116
120
|
|
|
117
121
|
// Quick read - get all data
|
|
118
|
-
const blob = await client.getFile(
|
|
122
|
+
const blob = await client.getFile("data/sales.parquet");
|
|
119
123
|
const data = await readParquet(blob, 1000); // Read first 1000 rows
|
|
120
124
|
console.log(data.columns);
|
|
121
125
|
console.log(data.rows);
|
|
122
126
|
|
|
123
127
|
// Advanced - query with SQL
|
|
124
|
-
const reader = new ParquetReader(
|
|
128
|
+
const reader = new ParquetReader("sales");
|
|
125
129
|
await reader.registerParquet(blob);
|
|
126
130
|
|
|
127
131
|
const result = await reader.query(`
|
|
@@ -132,7 +136,7 @@ const result = await reader.query(`
|
|
|
132
136
|
LIMIT 10
|
|
133
137
|
`);
|
|
134
138
|
|
|
135
|
-
console.log(
|
|
139
|
+
console.log("Top 10 products:", result.rows);
|
|
136
140
|
await reader.close();
|
|
137
141
|
```
|
|
138
142
|
|
|
@@ -169,7 +173,7 @@ function Dashboard() {
|
|
|
169
173
|
### Displaying Parquet Data
|
|
170
174
|
|
|
171
175
|
```typescript
|
|
172
|
-
import { ParquetReader } from
|
|
176
|
+
import { ParquetReader } from "@oxy/sdk";
|
|
173
177
|
|
|
174
178
|
function DataTable({ filePath }: { filePath: string }) {
|
|
175
179
|
const [data, setData] = useState(null);
|
|
@@ -192,29 +196,42 @@ function DataTable({ filePath }: { filePath: string }) {
|
|
|
192
196
|
|
|
193
197
|
## Use with v0 and Other Sandbox Services
|
|
194
198
|
|
|
195
|
-
Perfect for integrating Oxy data into v0-generated apps or other sandbox environments
|
|
199
|
+
Perfect for integrating Oxy data into v0-generated apps or other sandbox environments.
|
|
200
|
+
|
|
201
|
+
**For AI Assistants (v0.dev, Cursor, etc.):** See [.v0/rules.md](.v0/rules.md) and [.cursorrules](.cursorrules) for comprehensive integration guidelines.
|
|
196
202
|
|
|
197
203
|
```typescript
|
|
198
204
|
// In your v0 app
|
|
199
|
-
import { OxyClient, createConfig, readParquet } from
|
|
205
|
+
import { OxyClient, createConfig, readParquet } from "@oxy/sdk";
|
|
200
206
|
|
|
201
207
|
// Configure with environment variables set in v0 project settings
|
|
202
208
|
const client = new OxyClient(createConfig());
|
|
203
209
|
|
|
204
210
|
export async function fetchDashboardData() {
|
|
205
211
|
const [sales, customers] = await Promise.all([
|
|
206
|
-
client.getAppData(
|
|
207
|
-
client.getAppData(
|
|
212
|
+
client.getAppData("apps/sales.app.yml"),
|
|
213
|
+
client.getAppData("apps/customers.app.yml"),
|
|
208
214
|
]);
|
|
209
215
|
|
|
210
216
|
return { sales: sales.data, customers: customers.data };
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
export function getSalesChartUrl() {
|
|
214
|
-
return client.getFileUrl(
|
|
220
|
+
return client.getFileUrl("charts/sales-overview.png");
|
|
215
221
|
}
|
|
216
222
|
```
|
|
217
223
|
|
|
224
|
+
### v0 Environment Setup
|
|
225
|
+
|
|
226
|
+
In your v0 project settings, configure these environment variables:
|
|
227
|
+
|
|
228
|
+
```env
|
|
229
|
+
OXY_URL=https://api.oxy.tech
|
|
230
|
+
OXY_API_KEY=your-api-key-here
|
|
231
|
+
OXY_PROJECT_ID=your-project-uuid-here
|
|
232
|
+
OXY_BRANCH=main
|
|
233
|
+
```
|
|
234
|
+
|
|
218
235
|
## API Reference
|
|
219
236
|
|
|
220
237
|
### OxyClient
|
|
@@ -333,3 +350,7 @@ MIT
|
|
|
333
350
|
## Support
|
|
334
351
|
|
|
335
352
|
For issues and questions, please visit [GitHub Issues](https://github.com/dataframehq/oxy-internal/issues).
|
|
353
|
+
|
|
354
|
+
### Local development with v0 or cloud service
|
|
355
|
+
|
|
356
|
+
- Disable the local network access check [flag](chrome ://flags/#local-network-access-check)
|
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
|
-
const require_postMessage = require('./postMessage-
|
|
29
|
+
const require_postMessage = require('./postMessage-B1J0jDRN.cjs');
|
|
30
30
|
let _duckdb_duckdb_wasm = require("@duckdb/duckdb-wasm");
|
|
31
31
|
_duckdb_duckdb_wasm = __toESM(_duckdb_duckdb_wasm);
|
|
32
32
|
|
|
@@ -94,25 +94,40 @@ function createConfig(overrides) {
|
|
|
94
94
|
* ```
|
|
95
95
|
*/
|
|
96
96
|
async function createConfigAsync(overrides) {
|
|
97
|
-
const { isInIframe: isInIframe$1
|
|
97
|
+
const { isInIframe: isInIframe$1 } = await Promise.resolve().then(() => require("./postMessage-BSNS3ccd.cjs"));
|
|
98
98
|
let baseUrl = overrides?.baseUrl || process.env.OXY_URL;
|
|
99
99
|
let apiKey = overrides?.apiKey || process.env.OXY_API_KEY;
|
|
100
100
|
let projectId = overrides?.projectId || process.env.OXY_PROJECT_ID;
|
|
101
101
|
const disableAutoAuth = overrides?.disableAutoAuth ?? false;
|
|
102
102
|
const parentOrigin = overrides?.parentOrigin;
|
|
103
|
-
if (!disableAutoAuth && isInIframe$1() && !apiKey) if (!parentOrigin)
|
|
104
|
-
else
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
apiKey = authResult.apiKey;
|
|
110
|
-
if (authResult.projectId) projectId = authResult.projectId;
|
|
111
|
-
if (authResult.baseUrl) baseUrl = authResult.baseUrl;
|
|
112
|
-
console.log("[Oxy SDK] Successfully authenticated via postMessage");
|
|
113
|
-
} catch (error) {
|
|
103
|
+
if (!disableAutoAuth && isInIframe$1() && !apiKey) if (!parentOrigin) logWarningAboutMissingParentOrigin();
|
|
104
|
+
else apiKey = await attemptPostMessageAuth(parentOrigin, overrides?.timeout || 5e3, apiKey, projectId, baseUrl).then((result) => {
|
|
105
|
+
if (result.projectId) projectId = result.projectId;
|
|
106
|
+
if (result.baseUrl) baseUrl = result.baseUrl;
|
|
107
|
+
return result.apiKey;
|
|
108
|
+
}).catch((error) => {
|
|
114
109
|
console.error("[Oxy SDK] Failed to authenticate via postMessage:", error.message);
|
|
115
|
-
|
|
110
|
+
return apiKey;
|
|
111
|
+
});
|
|
112
|
+
return createFinalConfig(baseUrl, apiKey, projectId, overrides);
|
|
113
|
+
}
|
|
114
|
+
function logWarningAboutMissingParentOrigin() {
|
|
115
|
+
console.warn("[Oxy SDK] Running in iframe without API key and no parentOrigin specified. PostMessage authentication will be skipped. Provide parentOrigin config to enable automatic authentication.");
|
|
116
|
+
}
|
|
117
|
+
async function attemptPostMessageAuth(parentOrigin, timeout, currentApiKey, currentProjectId, currentBaseUrl) {
|
|
118
|
+
const { requestAuthFromParent: requestAuthFromParent$1 } = await Promise.resolve().then(() => require("./postMessage-BSNS3ccd.cjs"));
|
|
119
|
+
const authResult = await requestAuthFromParent$1({
|
|
120
|
+
parentOrigin,
|
|
121
|
+
timeout
|
|
122
|
+
});
|
|
123
|
+
console.log("[Oxy SDK] Successfully authenticated via postMessage");
|
|
124
|
+
return {
|
|
125
|
+
apiKey: authResult.apiKey || currentApiKey,
|
|
126
|
+
projectId: authResult.projectId || currentProjectId,
|
|
127
|
+
baseUrl: authResult.baseUrl || currentBaseUrl
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function createFinalConfig(baseUrl, apiKey, projectId, overrides) {
|
|
116
131
|
if (!baseUrl) throw new Error("OXY_URL environment variable or baseUrl config is required");
|
|
117
132
|
if (!projectId) throw new Error("OXY_PROJECT_ID environment variable or projectId config is required");
|
|
118
133
|
return {
|
|
@@ -121,8 +136,8 @@ async function createConfigAsync(overrides) {
|
|
|
121
136
|
projectId,
|
|
122
137
|
branch: overrides?.branch || process.env.OXY_BRANCH,
|
|
123
138
|
timeout: overrides?.timeout || 3e4,
|
|
124
|
-
parentOrigin,
|
|
125
|
-
disableAutoAuth
|
|
139
|
+
parentOrigin: overrides?.parentOrigin,
|
|
140
|
+
disableAutoAuth: overrides?.disableAutoAuth
|
|
126
141
|
};
|
|
127
142
|
}
|
|
128
143
|
|
|
@@ -130,6 +145,15 @@ async function createConfigAsync(overrides) {
|
|
|
130
145
|
//#region src/parquet.ts
|
|
131
146
|
let dbInstance = null;
|
|
132
147
|
let connection = null;
|
|
148
|
+
let operationQueue = Promise.resolve();
|
|
149
|
+
/**
|
|
150
|
+
* Enqueue an operation to prevent race conditions on shared DuckDB instance
|
|
151
|
+
*/
|
|
152
|
+
function enqueueOperation(operation) {
|
|
153
|
+
const currentOperation = operationQueue.then(operation, operation);
|
|
154
|
+
operationQueue = currentOperation.then(() => {}, () => {});
|
|
155
|
+
return currentOperation;
|
|
156
|
+
}
|
|
133
157
|
/**
|
|
134
158
|
* Initialize DuckDB-WASM instance
|
|
135
159
|
*/
|
|
@@ -160,6 +184,7 @@ var ParquetReader = class {
|
|
|
160
184
|
constructor(tableName = "data") {
|
|
161
185
|
this.registered = false;
|
|
162
186
|
this.tableName = tableName;
|
|
187
|
+
this.internalTableName = `${tableName}_${`${Date.now()}_${Math.random().toString(36).substring(2, 9)}`}`;
|
|
163
188
|
}
|
|
164
189
|
/**
|
|
165
190
|
* Register a Parquet file from a Blob
|
|
@@ -174,16 +199,18 @@ var ParquetReader = class {
|
|
|
174
199
|
* ```
|
|
175
200
|
*/
|
|
176
201
|
async registerParquet(blob) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
202
|
+
await enqueueOperation(async () => {
|
|
203
|
+
const conn = await getConnection();
|
|
204
|
+
const db = await initializeDuckDB();
|
|
205
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
206
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
207
|
+
await db.registerFileBuffer(`${this.internalTableName}.parquet`, uint8Array);
|
|
208
|
+
try {
|
|
209
|
+
await conn.query(`DROP TABLE IF EXISTS ${this.internalTableName}`);
|
|
210
|
+
} catch {}
|
|
211
|
+
await conn.query(`CREATE TABLE ${this.internalTableName} AS SELECT * FROM '${this.internalTableName}.parquet'`);
|
|
212
|
+
this.registered = true;
|
|
213
|
+
});
|
|
187
214
|
}
|
|
188
215
|
/**
|
|
189
216
|
* Execute a SQL query against the registered Parquet data
|
|
@@ -200,22 +227,26 @@ var ParquetReader = class {
|
|
|
200
227
|
*/
|
|
201
228
|
async query(sql) {
|
|
202
229
|
if (!this.registered) throw new Error("Parquet file not registered. Call registerParquet() first.");
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
row
|
|
230
|
+
return enqueueOperation(async () => {
|
|
231
|
+
const conn = await getConnection();
|
|
232
|
+
const rewrittenSql = sql.replace(new RegExp(`\\b${this.tableName}\\b`, "g"), this.internalTableName);
|
|
233
|
+
const result = await conn.query(rewrittenSql);
|
|
234
|
+
const columns = result.schema.fields.map((field) => field.name);
|
|
235
|
+
const rows = [];
|
|
236
|
+
for (let i = 0; i < result.numRows; i++) {
|
|
237
|
+
const row = [];
|
|
238
|
+
for (let j = 0; j < result.numCols; j++) {
|
|
239
|
+
const col = result.getChildAt(j);
|
|
240
|
+
row.push(col?.get(i));
|
|
241
|
+
}
|
|
242
|
+
rows.push(row);
|
|
211
243
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
};
|
|
244
|
+
return {
|
|
245
|
+
columns,
|
|
246
|
+
rows,
|
|
247
|
+
rowCount: result.numRows
|
|
248
|
+
};
|
|
249
|
+
});
|
|
219
250
|
}
|
|
220
251
|
/**
|
|
221
252
|
* Get all data from the registered table
|
|
@@ -266,17 +297,17 @@ var ParquetReader = class {
|
|
|
266
297
|
* Close and cleanup resources
|
|
267
298
|
*/
|
|
268
299
|
async close() {
|
|
269
|
-
if (this.registered) {
|
|
300
|
+
if (this.registered) await enqueueOperation(async () => {
|
|
270
301
|
const conn = await getConnection();
|
|
271
302
|
const db = await initializeDuckDB();
|
|
272
303
|
try {
|
|
273
|
-
await conn.query(`DROP TABLE IF EXISTS ${this.
|
|
274
|
-
} catch
|
|
304
|
+
await conn.query(`DROP TABLE IF EXISTS ${this.internalTableName}`);
|
|
305
|
+
} catch {}
|
|
275
306
|
try {
|
|
276
|
-
await db.dropFile(`${this.
|
|
277
|
-
} catch
|
|
307
|
+
await db.dropFile(`${this.internalTableName}.parquet`);
|
|
308
|
+
} catch {}
|
|
278
309
|
this.registered = false;
|
|
279
|
-
}
|
|
310
|
+
});
|
|
280
311
|
}
|
|
281
312
|
};
|
|
282
313
|
/**
|
|
@@ -398,7 +429,7 @@ var OxyClient = class OxyClient {
|
|
|
398
429
|
return response.json();
|
|
399
430
|
} catch (error) {
|
|
400
431
|
clearTimeout(timeoutId);
|
|
401
|
-
if (error.name === "AbortError") throw new Error(`Request timeout after ${this.config.timeout || 3e4}ms`);
|
|
432
|
+
if (error instanceof Error && error.name === "AbortError") throw new Error(`Request timeout after ${this.config.timeout || 3e4}ms`);
|
|
402
433
|
throw error;
|
|
403
434
|
}
|
|
404
435
|
}
|
|
@@ -519,7 +550,7 @@ var OxyClient = class OxyClient {
|
|
|
519
550
|
async getFile(filePath) {
|
|
520
551
|
const pathb64 = this.encodePathBase64(filePath);
|
|
521
552
|
const query = this.buildQueryParams();
|
|
522
|
-
return this.request(`/${this.config.projectId}/app/file/${pathb64}${query}`, { headers: {
|
|
553
|
+
return this.request(`/${this.config.projectId}/app/file/${pathb64}${query}`, { headers: { Accept: "application/octet-stream" } });
|
|
523
554
|
}
|
|
524
555
|
/**
|
|
525
556
|
* Gets a file URL for direct browser access
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isInIframe","requestAuthFromParent","duckdb"],"sources":["../src/config.ts","../src/parquet.ts","../src/client.ts"],"sourcesContent":["/**\n * Configuration for the Oxy SDK\n */\nexport interface OxyConfig {\n /**\n * Base URL of the Oxy API (e.g., 'https://api.oxy.tech' or 'http://localhost:3000')\n */\n baseUrl: string;\n\n /**\n * API key for authentication (optional for local development)\n */\n apiKey?: string;\n\n /**\n * Project ID (UUID)\n */\n projectId: string;\n\n /**\n * Optional branch name (defaults to current branch if not specified)\n */\n branch?: string;\n\n /**\n * Request timeout in milliseconds (default: 30000)\n */\n timeout?: number;\n\n /**\n * Parent window origin for postMessage authentication (iframe scenarios)\n * Required when using postMessage auth for security.\n * Example: 'https://app.example.com'\n * Use '*' only in development!\n */\n parentOrigin?: string;\n\n /**\n * Disable automatic postMessage authentication even if in iframe\n * Set to true if you want to provide API key manually in iframe context\n */\n disableAutoAuth?: boolean;\n}\n\n/**\n * Creates an Oxy configuration from environment variables\n *\n * Environment variables:\n * - OXY_URL: Base URL of the Oxy API\n * - OXY_API_KEY: API key for authentication\n * - OXY_PROJECT_ID: Project ID (UUID)\n * - OXY_BRANCH: (Optional) Branch name\n *\n * @param overrides - Optional configuration overrides\n * @returns OxyConfig object\n * @throws Error if required environment variables are missing\n */\nexport function createConfig(overrides?: Partial<OxyConfig>): OxyConfig {\n const baseUrl = overrides?.baseUrl || process.env.OXY_URL;\n const apiKey = overrides?.apiKey || process.env.OXY_API_KEY;\n const projectId = overrides?.projectId || process.env.OXY_PROJECT_ID;\n\n if (!baseUrl) {\n throw new Error('OXY_URL environment variable or baseUrl config is required');\n }\n\n if (!projectId) {\n throw new Error('OXY_PROJECT_ID environment variable or projectId config is required');\n }\n\n return {\n baseUrl: baseUrl.replace(/\\/$/, ''), // Remove trailing slash\n apiKey,\n projectId,\n branch: overrides?.branch || process.env.OXY_BRANCH,\n timeout: overrides?.timeout || 30000,\n parentOrigin: overrides?.parentOrigin,\n disableAutoAuth: overrides?.disableAutoAuth,\n };\n}\n\n/**\n * Creates an Oxy configuration asynchronously with support for postMessage authentication\n *\n * This is the recommended method for iframe scenarios where authentication\n * needs to be obtained from the parent window via postMessage.\n *\n * When running in an iframe without an API key, this function will:\n * 1. Detect the iframe context\n * 2. Send an authentication request to the parent window\n * 3. Wait for the parent to respond with credentials\n * 4. Return the configured client\n *\n * Environment variables (fallback):\n * - OXY_URL: Base URL of the Oxy API\n * - OXY_API_KEY: API key for authentication\n * - OXY_PROJECT_ID: Project ID (UUID)\n * - OXY_BRANCH: (Optional) Branch name\n *\n * @param overrides - Optional configuration overrides\n * @returns Promise resolving to OxyConfig object\n * @throws Error if required configuration is missing\n * @throws PostMessageAuthTimeoutError if parent doesn't respond\n *\n * @example\n * ```typescript\n * // Automatic iframe detection and authentication\n * const config = await createConfigAsync({\n * parentOrigin: 'https://app.example.com',\n * projectId: 'my-project-id',\n * baseUrl: 'https://api.oxy.tech'\n * });\n * ```\n */\nexport async function createConfigAsync(\n overrides?: Partial<OxyConfig>\n): Promise<OxyConfig> {\n // Import postMessage utilities (dynamic to avoid circular deps)\n const { isInIframe, requestAuthFromParent } = await import('./auth/postMessage');\n\n // Start with environment variables and overrides\n let baseUrl = overrides?.baseUrl || process.env.OXY_URL;\n let apiKey = overrides?.apiKey || process.env.OXY_API_KEY;\n let projectId = overrides?.projectId || process.env.OXY_PROJECT_ID;\n\n const disableAutoAuth = overrides?.disableAutoAuth ?? false;\n const parentOrigin = overrides?.parentOrigin;\n\n // Automatic iframe detection and authentication\n if (!disableAutoAuth && isInIframe() && !apiKey) {\n if (!parentOrigin) {\n console.warn(\n '[Oxy SDK] Running in iframe without API key and no parentOrigin specified. ' +\n 'PostMessage authentication will be skipped. ' +\n 'Provide parentOrigin config to enable automatic authentication.'\n );\n } else {\n try {\n const authResult = await requestAuthFromParent({\n parentOrigin,\n timeout: overrides?.timeout || 5000,\n });\n\n apiKey = authResult.apiKey;\n if (authResult.projectId) {\n projectId = authResult.projectId;\n }\n if (authResult.baseUrl) {\n baseUrl = authResult.baseUrl;\n }\n\n console.log('[Oxy SDK] Successfully authenticated via postMessage');\n } catch (error) {\n console.error(\n '[Oxy SDK] Failed to authenticate via postMessage:',\n (error as Error).message\n );\n // Fall through to use environment variables if available\n }\n }\n }\n\n // Validation\n if (!baseUrl) {\n throw new Error('OXY_URL environment variable or baseUrl config is required');\n }\n\n if (!projectId) {\n throw new Error('OXY_PROJECT_ID environment variable or projectId config is required');\n }\n\n return {\n baseUrl: baseUrl.replace(/\\/$/, ''), // Remove trailing slash\n apiKey,\n projectId,\n branch: overrides?.branch || process.env.OXY_BRANCH,\n timeout: overrides?.timeout || 30000,\n parentOrigin,\n disableAutoAuth,\n };\n}\n","import * as duckdb from '@duckdb/duckdb-wasm';\n\nlet dbInstance: duckdb.AsyncDuckDB | null = null;\nlet connection: duckdb.AsyncDuckDBConnection | null = null;\n\n/**\n * Initialize DuckDB-WASM instance\n */\nexport async function initializeDuckDB(): Promise<duckdb.AsyncDuckDB> {\n if (dbInstance) {\n return dbInstance;\n }\n\n const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();\n\n // Select a bundle based on browser features\n const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);\n\n const worker_url = URL.createObjectURL(\n new Blob([`importScripts(\"${bundle.mainWorker}\");`], {\n type: 'text/javascript',\n })\n );\n\n const worker = new Worker(worker_url);\n const logger = new duckdb.ConsoleLogger();\n\n dbInstance = new duckdb.AsyncDuckDB(logger, worker);\n await dbInstance.instantiate(bundle.mainModule, bundle.pthreadWorker);\n URL.revokeObjectURL(worker_url);\n\n return dbInstance;\n}\n\n/**\n * Get or create a DuckDB connection\n */\nasync function getConnection(): Promise<duckdb.AsyncDuckDBConnection> {\n if (connection) {\n return connection;\n }\n\n const db = await initializeDuckDB();\n connection = await db.connect();\n return connection;\n}\n\n/**\n * Query result interface\n */\nexport interface QueryResult {\n columns: string[];\n rows: any[][];\n rowCount: number;\n}\n\n/**\n * ParquetReader provides methods to read and query Parquet files\n */\nexport class ParquetReader {\n private tableName: string;\n private registered: boolean = false;\n\n constructor(tableName: string = 'data') {\n this.tableName = tableName;\n }\n\n /**\n * Register a Parquet file from a Blob\n *\n * @param blob - Parquet file as Blob\n *\n * @example\n * ```typescript\n * const blob = await client.getFile('data/sales.parquet');\n * const reader = new ParquetReader('sales');\n * await reader.registerParquet(blob);\n * ```\n */\n async registerParquet(blob: Blob): Promise<void> {\n const conn = await getConnection();\n const db = await initializeDuckDB();\n\n // Convert blob to Uint8Array\n const arrayBuffer = await blob.arrayBuffer();\n const uint8Array = new Uint8Array(arrayBuffer);\n\n // Register the file with DuckDB\n await db.registerFileBuffer(\n `${this.tableName}.parquet`,\n uint8Array\n );\n\n // Drop table if it exists\n try {\n await conn.query(`DROP TABLE IF EXISTS ${this.tableName}`);\n } catch (e) {\n // Ignore error if table doesn't exist\n }\n\n // Create table from parquet\n await conn.query(\n `CREATE TABLE ${this.tableName} AS SELECT * FROM '${this.tableName}.parquet'`\n );\n\n this.registered = true;\n }\n\n /**\n * Execute a SQL query against the registered Parquet data\n *\n * @param sql - SQL query string\n * @returns Query result with columns and rows\n *\n * @example\n * ```typescript\n * const result = await reader.query('SELECT * FROM sales LIMIT 10');\n * console.log(result.columns);\n * console.log(result.rows);\n * ```\n */\n async query(sql: string): Promise<QueryResult> {\n if (!this.registered) {\n throw new Error('Parquet file not registered. Call registerParquet() first.');\n }\n\n const conn = await getConnection();\n const result = await conn.query(sql);\n\n const columns = result.schema.fields.map((field) => field.name);\n const rows: any[][] = [];\n\n // Convert Arrow table to rows\n for (let i = 0; i < result.numRows; i++) {\n const row: any[] = [];\n for (let j = 0; j < result.numCols; j++) {\n const col = result.getChildAt(j);\n row.push(col?.get(i));\n }\n rows.push(row);\n }\n\n return {\n columns,\n rows,\n rowCount: result.numRows,\n };\n }\n\n /**\n * Get all data from the registered table\n *\n * @param limit - Maximum number of rows to return (default: all)\n * @returns Query result\n *\n * @example\n * ```typescript\n * const allData = await reader.getAll();\n * const first100 = await reader.getAll(100);\n * ```\n */\n async getAll(limit?: number): Promise<QueryResult> {\n const limitClause = limit ? ` LIMIT ${limit}` : '';\n return this.query(`SELECT * FROM ${this.tableName}${limitClause}`);\n }\n\n /**\n * Get table schema information\n *\n * @returns Schema information\n *\n * @example\n * ```typescript\n * const schema = await reader.getSchema();\n * console.log(schema.columns); // ['id', 'name', 'sales']\n * console.log(schema.rows); // [['id', 'INTEGER'], ['name', 'VARCHAR'], ...]\n * ```\n */\n async getSchema(): Promise<QueryResult> {\n return this.query(`DESCRIBE ${this.tableName}`);\n }\n\n /**\n * Get row count\n *\n * @returns Number of rows in the table\n *\n * @example\n * ```typescript\n * const count = await reader.count();\n * console.log(`Total rows: ${count}`);\n * ```\n */\n async count(): Promise<number> {\n const result = await this.query(`SELECT COUNT(*) as count FROM ${this.tableName}`);\n return result.rows[0][0];\n }\n\n /**\n * Close and cleanup resources\n */\n async close(): Promise<void> {\n if (this.registered) {\n const conn = await getConnection();\n const db = await initializeDuckDB();\n\n // Drop the table\n try {\n await conn.query(`DROP TABLE IF EXISTS ${this.tableName}`);\n } catch (e) {\n // Ignore error\n }\n\n // Drop the registered file buffer\n try {\n await db.dropFile(`${this.tableName}.parquet`);\n } catch (e) {\n // Ignore error if file doesn't exist\n }\n\n this.registered = false;\n }\n }\n}\n\n/**\n * Helper function to quickly read a Parquet blob and execute a query\n *\n * @param blob - Parquet file as Blob\n * @param sql - SQL query to execute (optional, defaults to SELECT *)\n * @returns Query result\n *\n * @example\n * ```typescript\n * const blob = await client.getFile('data/sales.parquet');\n * const result = await queryParquet(blob, 'SELECT product, SUM(amount) as total FROM data GROUP BY product');\n * console.log(result);\n * ```\n */\nexport async function queryParquet(\n blob: Blob,\n sql?: string\n): Promise<QueryResult> {\n // Generate unique table name to avoid conflicts\n const uniqueId = `temp_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n const reader = new ParquetReader(uniqueId);\n\n await reader.registerParquet(blob);\n\n const query = sql || `SELECT * FROM ${uniqueId}`;\n const result = await reader.query(query);\n\n await reader.close();\n return result;\n}\n\n/**\n * Helper function to read Parquet file and get all data\n *\n * @param blob - Parquet file as Blob\n * @param limit - Maximum number of rows (optional)\n * @returns Query result\n *\n * @example\n * ```typescript\n * const blob = await client.getFile('data/sales.parquet');\n * const data = await readParquet(blob, 1000);\n * console.log(`Loaded ${data.rowCount} rows`);\n * ```\n */\nexport async function readParquet(\n blob: Blob,\n limit?: number\n): Promise<QueryResult> {\n // Generate unique table name to avoid conflicts\n const uniqueId = `temp_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n const reader = new ParquetReader(uniqueId);\n\n await reader.registerParquet(blob);\n\n const result = await reader.getAll(limit);\n\n await reader.close();\n return result;\n}\n","import { OxyConfig, createConfigAsync } from './config';\nimport {\n AppItem,\n AppDataResponse,\n GetDisplaysResponse,\n ApiError,\n TableData,\n} from './types';\nimport { readParquet } from './parquet';\n\n/**\n * Oxy API Client for interacting with Oxy data\n */\nexport class OxyClient {\n private config: OxyConfig;\n\n constructor(config: OxyConfig) {\n this.config = config;\n }\n\n /**\n * Creates an OxyClient instance asynchronously with support for postMessage authentication\n *\n * This is the recommended method when using the SDK in an iframe that needs to\n * obtain authentication from the parent window via postMessage.\n *\n * @param config - Optional configuration overrides\n * @returns Promise resolving to OxyClient instance\n * @throws Error if required configuration is missing\n * @throws PostMessageAuthTimeoutError if parent doesn't respond\n *\n * @example\n * ```typescript\n * // In an iframe - automatic postMessage auth\n * const client = await OxyClient.create({\n * parentOrigin: 'https://app.example.com',\n * projectId: 'my-project-id',\n * baseUrl: 'https://api.oxy.tech'\n * });\n *\n * // Use the client normally\n * const apps = await client.listApps();\n * ```\n */\n static async create(config?: Partial<OxyConfig>): Promise<OxyClient> {\n const resolvedConfig = await createConfigAsync(config);\n return new OxyClient(resolvedConfig);\n }\n\n /**\n * Encodes a file path to base64 for use in API URLs\n */\n private encodePathBase64(path: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js environment\n return Buffer.from(path).toString('base64');\n } else {\n // Browser environment\n return btoa(path);\n }\n }\n\n /**\n * Makes an authenticated HTTP request to the Oxy API\n */\n private async request<T>(\n endpoint: string,\n options: RequestInit = {}\n ): Promise<T> {\n const url = `${this.config.baseUrl}${endpoint}`;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...((options.headers as Record<string, string>) || {}),\n };\n\n // Only add Authorization header if API key is provided (optional for local dev)\n if (this.config.apiKey) {\n headers['Authorization'] = `Bearer ${this.config.apiKey}`;\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.config.timeout || 30000);\n\n try {\n const response = await fetch(url, {\n ...options,\n headers,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => 'Unknown error');\n const error: ApiError = {\n message: `API request failed: ${response.statusText}`,\n status: response.status,\n details: errorText,\n };\n throw error;\n }\n\n // Handle binary responses\n const acceptHeader =\n typeof options.headers === 'object' && options.headers !== null\n ? (options.headers as Record<string, string>)['Accept']\n : undefined;\n if (acceptHeader === 'application/octet-stream') {\n return response.blob() as Promise<T>;\n }\n\n return response.json();\n } catch (error: any) {\n clearTimeout(timeoutId);\n\n if (error.name === 'AbortError') {\n throw new Error(`Request timeout after ${this.config.timeout || 30000}ms`);\n }\n\n throw error;\n }\n }\n\n /**\n * Builds query parameters including optional branch\n */\n private buildQueryParams(additionalParams: Record<string, string> = {}): string {\n const params: Record<string, string> = { ...additionalParams };\n\n if (this.config.branch) {\n params.branch = this.config.branch;\n }\n\n const searchParams = new URLSearchParams(params);\n const queryString = searchParams.toString();\n return queryString ? `?${queryString}` : '';\n }\n\n /**\n * Lists all apps in the project\n *\n * @returns Array of app items\n *\n * @example\n * ```typescript\n * const apps = await client.listApps();\n * console.log('Available apps:', apps);\n * ```\n */\n async listApps(): Promise<AppItem[]> {\n const query = this.buildQueryParams();\n return this.request<AppItem[]>(`/${this.config.projectId}/app${query}`);\n }\n\n /**\n * Gets data for a specific app\n *\n * @param appPath - Relative path to the app file (e.g., 'my-app.app.yml')\n * @returns App data response\n *\n * @example\n * ```typescript\n * const data = await client.getAppData('dashboard.app.yml');\n * if (data.error) {\n * console.error('Error:', data.error);\n * } else {\n * console.log('App data:', data.data);\n * }\n * ```\n */\n async getAppData(appPath: string): Promise<AppDataResponse> {\n const pathb64 = this.encodePathBase64(appPath);\n const query = this.buildQueryParams();\n return this.request<AppDataResponse>(\n `/${this.config.projectId}/app/${pathb64}${query}`\n );\n }\n\n /**\n * Runs an app and returns fresh data (bypasses cache)\n *\n * @param appPath - Relative path to the app file\n * @returns App data response\n *\n * @example\n * ```typescript\n * const data = await client.runApp('dashboard.app.yml');\n * console.log('Fresh app data:', data.data);\n * ```\n */\n async runApp(appPath: string): Promise<AppDataResponse> {\n const pathb64 = this.encodePathBase64(appPath);\n const query = this.buildQueryParams();\n return this.request<AppDataResponse>(\n `/${this.config.projectId}/app/${pathb64}/run${query}`,\n { method: 'POST' }\n );\n }\n\n /**\n * Gets display configurations for an app\n *\n * @param appPath - Relative path to the app file\n * @returns Display configurations with potential errors\n *\n * @example\n * ```typescript\n * const displays = await client.getDisplays('dashboard.app.yml');\n * displays.displays.forEach(d => {\n * if (d.error) {\n * console.error('Display error:', d.error);\n * } else {\n * console.log('Display:', d.display);\n * }\n * });\n * ```\n */\n async getDisplays(appPath: string): Promise<GetDisplaysResponse> {\n const pathb64 = this.encodePathBase64(appPath);\n const query = this.buildQueryParams();\n return this.request<GetDisplaysResponse>(\n `/${this.config.projectId}/app/${pathb64}/displays${query}`\n );\n }\n\n /**\n * Gets a file from the app state directory (e.g., generated charts, images)\n *\n * This is useful for retrieving generated assets like charts, images, or other\n * files produced by app workflows and stored in the state directory.\n *\n * @param filePath - Relative path to the file in state directory\n * @returns Blob containing the file data\n *\n * @example\n * ```typescript\n * // Get a generated chart image\n * const blob = await client.getFile('charts/sales-chart.png');\n * const imageUrl = URL.createObjectURL(blob);\n *\n * // Use in an img tag\n * document.querySelector('img').src = imageUrl;\n * ```\n *\n * @example\n * ```typescript\n * // Download a file\n * const blob = await client.getFile('exports/data.csv');\n * const a = document.createElement('a');\n * a.href = URL.createObjectURL(blob);\n * a.download = 'data.csv';\n * a.click();\n * ```\n */\n async getFile(filePath: string): Promise<Blob> {\n const pathb64 = this.encodePathBase64(filePath);\n const query = this.buildQueryParams();\n return this.request<Blob>(\n `/${this.config.projectId}/app/file/${pathb64}${query}`,\n {\n headers: {\n 'Accept': 'application/octet-stream',\n },\n }\n );\n }\n\n /**\n * Gets a file URL for direct browser access\n *\n * This returns a URL that can be used directly in img tags, fetch calls, etc.\n * The URL includes authentication via query parameters.\n *\n * @param filePath - Relative path to the file in state directory\n * @returns Full URL to the file\n *\n * @example\n * ```typescript\n * const imageUrl = client.getFileUrl('charts/sales-chart.png');\n *\n * // Use directly in img tag (in environments where query-based auth is supported)\n * document.querySelector('img').src = imageUrl;\n * ```\n */\n getFileUrl(filePath: string): string {\n const pathb64 = this.encodePathBase64(filePath);\n const query = this.buildQueryParams();\n return `${this.config.baseUrl}/${this.config.projectId}/app/file/${pathb64}${query}`;\n }\n\n /**\n * Fetches a parquet file and parses it into table data\n *\n * @param filePath - Relative path to the parquet file\n * @param limit - Maximum number of rows to return (default: 100)\n * @returns TableData with columns and rows\n *\n * @example\n * ```typescript\n * const tableData = await client.getTableData('data/sales.parquet', 50);\n * console.log(tableData.columns);\n * console.log(tableData.rows);\n * console.log(`Total rows: ${tableData.total_rows}`);\n * ```\n */\n async getTableData(filePath: string, limit: number = 100): Promise<TableData> {\n const blob = await this.getFile(filePath);\n const result = await readParquet(blob, limit);\n\n return {\n columns: result.columns,\n rows: result.rows,\n total_rows: result.rowCount,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,aAAa,WAA2C;CACtE,MAAM,UAAU,WAAW,WAAW,QAAQ,IAAI;CAClD,MAAM,SAAS,WAAW,UAAU,QAAQ,IAAI;CAChD,MAAM,YAAY,WAAW,aAAa,QAAQ,IAAI;AAEtD,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,6DAA6D;AAG/E,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,sEAAsE;AAGxF,QAAO;EACL,SAAS,QAAQ,QAAQ,OAAO,GAAG;EACnC;EACA;EACA,QAAQ,WAAW,UAAU,QAAQ,IAAI;EACzC,SAAS,WAAW,WAAW;EAC/B,cAAc,WAAW;EACzB,iBAAiB,WAAW;EAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCH,eAAsB,kBACpB,WACoB;CAEpB,MAAM,EAAE,0BAAY,mDAA0B,2CAAM;CAGpD,IAAI,UAAU,WAAW,WAAW,QAAQ,IAAI;CAChD,IAAI,SAAS,WAAW,UAAU,QAAQ,IAAI;CAC9C,IAAI,YAAY,WAAW,aAAa,QAAQ,IAAI;CAEpD,MAAM,kBAAkB,WAAW,mBAAmB;CACtD,MAAM,eAAe,WAAW;AAGhC,KAAI,CAAC,mBAAmBA,cAAY,IAAI,CAAC,OACvC,KAAI,CAAC,aACH,SAAQ,KACN,yLAGD;KAED,KAAI;EACF,MAAM,aAAa,MAAMC,wBAAsB;GAC7C;GACA,SAAS,WAAW,WAAW;GAChC,CAAC;AA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OAAO,UAAU,OAAO,UAAU,QAC5C;;;;;;;;;;;;;;CAeH,MAAM,OAAO,SAA2C;EACtD,MAAM,UAAU,KAAK,iBAAiB,QAAQ;EAC9C,MAAM,QAAQ,KAAK,kBAAkB;AACrC,SAAO,KAAK,QACV,IAAI,KAAK,OAAO,UAAU,OAAO,QAAQ,MAAM,SAC/C,EAAE,QAAQ,QAAQ,CACnB;;;;;;;;;;;;;;;;;;;;CAqBH,MAAM,YAAY,SAA+C;EAC/D,MAAM,UAAU,KAAK,iBAAiB,QAAQ;EAC9C,MAAM,QAAQ,KAAK,kBAAkB;AACrC,SAAO,KAAK,QACV,IAAI,KAAK,OAAO,UAAU,OAAO,QAAQ,WAAW,QACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCH,MAAM,QAAQ,UAAiC;EAC7C,MAAM,UAAU,KAAK,iBAAiB,SAAS;EAC/C,MAAM,QAAQ,KAAK,kBAAkB;AACrC,SAAO,KAAK,QACV,IAAI,KAAK,OAAO,UAAU,YAAY,UAAU,SAChD,EACE,SAAS,EACP,UAAU,4BACX,EACF,CACF;;;;;;;;;;;;;;;;;;;CAoBH,WAAW,UAA0B;EACnC,MAAM,UAAU,KAAK,iBAAiB,SAAS;EAC/C,MAAM,QAAQ,KAAK,kBAAkB;AACrC,SAAO,GAAG,KAAK,OAAO,QAAQ,GAAG,KAAK,OAAO,UAAU,YAAY,UAAU;;;;;;;;;;;;;;;;;CAkB/E,MAAM,aAAa,UAAkB,QAAgB,KAAyB;EAE5E,MAAM,SAAS,MAAM,YADR,MAAM,KAAK,QAAQ,SAAS,EACF,MAAM;AAE7C,SAAO;GACL,SAAS,OAAO;GAChB,MAAM,OAAO;GACb,YAAY,OAAO;GACpB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isInIframe","requestAuthFromParent","duckdb"],"sources":["../src/config.ts","../src/parquet.ts","../src/client.ts"],"sourcesContent":["/**\n * Configuration for the Oxy SDK\n */\nexport interface OxyConfig {\n /**\n * Base URL of the Oxy API (e.g., 'https://api.oxy.tech' or 'http://localhost:3000')\n */\n baseUrl: string;\n\n /**\n * API key for authentication (optional for local development)\n */\n apiKey?: string;\n\n /**\n * Project ID (UUID)\n */\n projectId: string;\n\n /**\n * Optional branch name (defaults to current branch if not specified)\n */\n branch?: string;\n\n /**\n * Request timeout in milliseconds (default: 30000)\n */\n timeout?: number;\n\n /**\n * Parent window origin for postMessage authentication (iframe scenarios)\n * Required when using postMessage auth for security.\n * Example: 'https://app.example.com'\n * Use '*' only in development!\n */\n parentOrigin?: string;\n\n /**\n * Disable automatic postMessage authentication even if in iframe\n * Set to true if you want to provide API key manually in iframe context\n */\n disableAutoAuth?: boolean;\n}\n\n/**\n * Creates an Oxy configuration from environment variables\n *\n * Environment variables:\n * - OXY_URL: Base URL of the Oxy API\n * - OXY_API_KEY: API key for authentication\n * - OXY_PROJECT_ID: Project ID (UUID)\n * - OXY_BRANCH: (Optional) Branch name\n *\n * @param overrides - Optional configuration overrides\n * @returns OxyConfig object\n * @throws Error if required environment variables are missing\n */\nexport function createConfig(overrides?: Partial<OxyConfig>): OxyConfig {\n const baseUrl = overrides?.baseUrl || process.env.OXY_URL;\n const apiKey = overrides?.apiKey || process.env.OXY_API_KEY;\n const projectId = overrides?.projectId || process.env.OXY_PROJECT_ID;\n\n if (!baseUrl) {\n throw new Error(\n \"OXY_URL environment variable or baseUrl config is required\",\n );\n }\n\n if (!projectId) {\n throw new Error(\n \"OXY_PROJECT_ID environment variable or projectId config is required\",\n );\n }\n\n return {\n baseUrl: baseUrl.replace(/\\/$/, \"\"), // Remove trailing slash\n apiKey,\n projectId,\n branch: overrides?.branch || process.env.OXY_BRANCH,\n timeout: overrides?.timeout || 30000,\n parentOrigin: overrides?.parentOrigin,\n disableAutoAuth: overrides?.disableAutoAuth,\n };\n}\n\n/**\n * Creates an Oxy configuration asynchronously with support for postMessage authentication\n *\n * This is the recommended method for iframe scenarios where authentication\n * needs to be obtained from the parent window via postMessage.\n *\n * When running in an iframe without an API key, this function will:\n * 1. Detect the iframe context\n * 2. Send an authentication request to the parent window\n * 3. Wait for the parent to respond with credentials\n * 4. Return the configured client\n *\n * Environment variables (fallback):\n * - OXY_URL: Base URL of the Oxy API\n * - OXY_API_KEY: API key for authentication\n * - OXY_PROJECT_ID: Project ID (UUID)\n * - OXY_BRANCH: (Optional) Branch name\n *\n * @param overrides - Optional configuration overrides\n * @returns Promise resolving to OxyConfig object\n * @throws Error if required configuration is missing\n * @throws PostMessageAuthTimeoutError if parent doesn't respond\n *\n * @example\n * ```typescript\n * // Automatic iframe detection and authentication\n * const config = await createConfigAsync({\n * parentOrigin: 'https://app.example.com',\n * projectId: 'my-project-id',\n * baseUrl: 'https://api.oxy.tech'\n * });\n * ```\n */\nexport async function createConfigAsync(\n overrides?: Partial<OxyConfig>,\n): Promise<OxyConfig> {\n // Import postMessage utilities (dynamic to avoid circular deps)\n const { isInIframe } = await import(\"./auth/postMessage\");\n\n // Start with environment variables and overrides\n let baseUrl = overrides?.baseUrl || process.env.OXY_URL;\n let apiKey = overrides?.apiKey || process.env.OXY_API_KEY;\n let projectId = overrides?.projectId || process.env.OXY_PROJECT_ID;\n\n const disableAutoAuth = overrides?.disableAutoAuth ?? false;\n const parentOrigin = overrides?.parentOrigin;\n\n // Automatic iframe detection and authentication\n if (!disableAutoAuth && isInIframe() && !apiKey) {\n if (!parentOrigin) {\n logWarningAboutMissingParentOrigin();\n } else {\n apiKey = await attemptPostMessageAuth(\n parentOrigin,\n overrides?.timeout || 5000,\n apiKey,\n projectId,\n baseUrl,\n )\n .then((result) => {\n if (result.projectId) projectId = result.projectId;\n if (result.baseUrl) baseUrl = result.baseUrl;\n return result.apiKey;\n })\n .catch((error) => {\n console.error(\n \"[Oxy SDK] Failed to authenticate via postMessage:\",\n (error as Error).message,\n );\n return apiKey;\n });\n }\n }\n\n return createFinalConfig(baseUrl, apiKey, projectId, overrides);\n}\n\nfunction logWarningAboutMissingParentOrigin(): void {\n console.warn(\n \"[Oxy SDK] Running in iframe without API key and no parentOrigin specified. \" +\n \"PostMessage authentication will be skipped. \" +\n \"Provide parentOrigin config to enable automatic authentication.\",\n );\n}\n\nasync function attemptPostMessageAuth(\n parentOrigin: string,\n timeout: number,\n currentApiKey: string | undefined,\n currentProjectId: string | undefined,\n currentBaseUrl: string | undefined,\n): Promise<{ apiKey?: string; projectId?: string; baseUrl?: string }> {\n const { requestAuthFromParent } = await import(\"./auth/postMessage\");\n const authResult = await requestAuthFromParent({ parentOrigin, timeout });\n\n console.log(\"[Oxy SDK] Successfully authenticated via postMessage\");\n\n return {\n apiKey: authResult.apiKey || currentApiKey,\n projectId: authResult.projectId || currentProjectId,\n baseUrl: authResult.baseUrl || currentBaseUrl,\n };\n}\n\nfunction createFinalConfig(\n baseUrl: string | undefined,\n apiKey: string | undefined,\n projectId: string | undefined,\n overrides?: Partial<OxyConfig>,\n): OxyConfig {\n // Validation\n if (!baseUrl) {\n throw new Error(\n \"OXY_URL environment variable or baseUrl config is required\",\n );\n }\n\n if (!projectId) {\n throw new Error(\n \"OXY_PROJECT_ID environment variable or projectId config is required\",\n );\n }\n\n return {\n baseUrl: baseUrl.replace(/\\/$/, \"\"), // Remove trailing slash\n apiKey,\n projectId,\n branch: overrides?.branch || process.env.OXY_BRANCH,\n timeout: overrides?.timeout || 30000,\n parentOrigin: overrides?.parentOrigin,\n disableAutoAuth: overrides?.disableAutoAuth,\n };\n}\n","import * as duckdb from \"@duckdb/duckdb-wasm\";\n\nlet dbInstance: duckdb.AsyncDuckDB | null = null;\nlet connection: duckdb.AsyncDuckDBConnection | null = null;\n\n// Queue to serialize operations and prevent race conditions\nlet operationQueue = Promise.resolve();\n\n/**\n * Enqueue an operation to prevent race conditions on shared DuckDB instance\n */\nfunction enqueueOperation<T>(operation: () => Promise<T>): Promise<T> {\n const currentOperation = operationQueue.then(operation, operation);\n operationQueue = currentOperation.then(\n () => {\n return;\n },\n () => {\n return;\n },\n );\n return currentOperation;\n}\n\n/**\n * Initialize DuckDB-WASM instance\n */\nexport async function initializeDuckDB(): Promise<duckdb.AsyncDuckDB> {\n if (dbInstance) {\n return dbInstance;\n }\n\n const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();\n\n // Select a bundle based on browser features\n const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);\n\n const worker_url = URL.createObjectURL(\n new Blob([`importScripts(\"${bundle.mainWorker}\");`], {\n type: \"text/javascript\",\n }),\n );\n\n const worker = new Worker(worker_url);\n const logger = new duckdb.ConsoleLogger();\n\n dbInstance = new duckdb.AsyncDuckDB(logger, worker);\n await dbInstance.instantiate(bundle.mainModule, bundle.pthreadWorker);\n URL.revokeObjectURL(worker_url);\n\n return dbInstance;\n}\n\n/**\n * Get or create a DuckDB connection\n */\nasync function getConnection(): Promise<duckdb.AsyncDuckDBConnection> {\n if (connection) {\n return connection;\n }\n\n const db = await initializeDuckDB();\n connection = await db.connect();\n return connection;\n}\n\n/**\n * Query result interface\n */\nexport interface QueryResult {\n columns: string[];\n rows: unknown[][];\n rowCount: number;\n}\n\n/**\n * ParquetReader provides methods to read and query Parquet files\n */\nexport class ParquetReader {\n private tableName: string;\n private internalTableName: string;\n private registered: boolean = false;\n\n constructor(tableName: string = \"data\") {\n this.tableName = tableName;\n // Generate unique internal table name to prevent conflicts between concurrent instances\n // Note: Math.random() is acceptable here as uniqueness is only needed for table naming (not security-critical)\n /* eslint-disable sonarjs/pseudo-random */\n const uniqueId = `${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n /* eslint-enable sonarjs/pseudo-random */\n this.internalTableName = `${tableName}_${uniqueId}`;\n }\n\n /**\n * Register a Parquet file from a Blob\n *\n * @param blob - Parquet file as Blob\n *\n * @example\n * ```typescript\n * const blob = await client.getFile('data/sales.parquet');\n * const reader = new ParquetReader('sales');\n * await reader.registerParquet(blob);\n * ```\n */\n async registerParquet(blob: Blob): Promise<void> {\n await enqueueOperation(async () => {\n const conn = await getConnection();\n const db = await initializeDuckDB();\n\n // Convert blob to Uint8Array\n const arrayBuffer = await blob.arrayBuffer();\n const uint8Array = new Uint8Array(arrayBuffer);\n\n // Register the file with DuckDB using unique name\n await db.registerFileBuffer(\n `${this.internalTableName}.parquet`,\n uint8Array,\n );\n\n // Drop table if it exists\n try {\n await conn.query(`DROP TABLE IF EXISTS ${this.internalTableName}`);\n } catch {\n // Ignore error if table doesn't exist\n }\n\n // Create table from parquet\n await conn.query(\n `CREATE TABLE ${this.internalTableName} AS SELECT * FROM '${this.internalTableName}.parquet'`,\n );\n\n this.registered = true;\n });\n }\n\n /**\n * Execute a SQL query against the registered Parquet data\n *\n * @param sql - SQL query string\n * @returns Query result with columns and rows\n *\n * @example\n * ```typescript\n * const result = await reader.query('SELECT * FROM sales LIMIT 10');\n * console.log(result.columns);\n * console.log(result.rows);\n * ```\n */\n async query(sql: string): Promise<QueryResult> {\n if (!this.registered) {\n throw new Error(\n \"Parquet file not registered. Call registerParquet() first.\",\n );\n }\n\n return enqueueOperation(async () => {\n const conn = await getConnection();\n\n // Replace user's table name with internal unique table name\n const rewrittenSql = sql.replace(\n new RegExp(`\\\\b${this.tableName}\\\\b`, \"g\"),\n this.internalTableName,\n );\n\n const result = await conn.query(rewrittenSql);\n\n const columns = result.schema.fields.map((field) => field.name);\n const rows: unknown[][] = [];\n\n // Convert Arrow table to rows\n for (let i = 0; i < result.numRows; i++) {\n const row: unknown[] = [];\n for (let j = 0; j < result.numCols; j++) {\n const col = result.getChildAt(j);\n row.push(col?.get(i));\n }\n rows.push(row);\n }\n\n return {\n columns,\n rows,\n rowCount: result.numRows,\n };\n });\n }\n\n /**\n * Get all data from the registered table\n *\n * @param limit - Maximum number of rows to return (default: all)\n * @returns Query result\n *\n * @example\n * ```typescript\n * const allData = await reader.getAll();\n * const first100 = await reader.getAll(100);\n * ```\n */\n async getAll(limit?: number): Promise<QueryResult> {\n const limitClause = limit ? ` LIMIT ${limit}` : \"\";\n return this.query(`SELECT * FROM ${this.tableName}${limitClause}`);\n }\n\n /**\n * Get table schema information\n *\n * @returns Schema information\n *\n * @example\n * ```typescript\n * const schema = await reader.getSchema();\n * console.log(schema.columns); // ['id', 'name', 'sales']\n * console.log(schema.rows); // [['id', 'INTEGER'], ['name', 'VARCHAR'], ...]\n * ```\n */\n async getSchema(): Promise<QueryResult> {\n return this.query(`DESCRIBE ${this.tableName}`);\n }\n\n /**\n * Get row count\n *\n * @returns Number of rows in the table\n *\n * @example\n * ```typescript\n * const count = await reader.count();\n * console.log(`Total rows: ${count}`);\n * ```\n */\n async count(): Promise<number> {\n const result = await this.query(\n `SELECT COUNT(*) as count FROM ${this.tableName}`,\n );\n return result.rows[0][0] as number;\n }\n\n /**\n * Close and cleanup resources\n */\n async close(): Promise<void> {\n if (this.registered) {\n await enqueueOperation(async () => {\n const conn = await getConnection();\n const db = await initializeDuckDB();\n\n // Drop the table using internal unique name\n try {\n await conn.query(`DROP TABLE IF EXISTS ${this.internalTableName}`);\n } catch {\n // Ignore error\n }\n\n // Drop the registered file buffer using internal unique name\n try {\n await db.dropFile(`${this.internalTableName}.parquet`);\n } catch {\n // Ignore error if file doesn't exist\n }\n\n this.registered = false;\n });\n }\n }\n}\n\n/**\n * Helper function to quickly read a Parquet blob and execute a query\n *\n * @param blob - Parquet file as Blob\n * @param sql - SQL query to execute (optional, defaults to SELECT *)\n * @returns Query result\n *\n * @example\n * ```typescript\n * const blob = await client.getFile('data/sales.parquet');\n * const result = await queryParquet(blob, 'SELECT product, SUM(amount) as total FROM data GROUP BY product');\n * console.log(result);\n * ```\n */\nexport async function queryParquet(\n blob: Blob,\n sql?: string,\n): Promise<QueryResult> {\n // Generate unique table name to avoid conflicts\n // Note: Math.random() is acceptable here as uniqueness is only needed for table naming (not security-critical)\n /* eslint-disable sonarjs/pseudo-random */\n const uniqueId = `temp_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n /* eslint-enable sonarjs/pseudo-random */\n const reader = new ParquetReader(uniqueId);\n\n await reader.registerParquet(blob);\n\n const query = sql || `SELECT * FROM ${uniqueId}`;\n const result = await reader.query(query);\n\n await reader.close();\n return result;\n}\n\n/**\n * Helper function to read Parquet file and get all data\n *\n * @param blob - Parquet file as Blob\n * @param limit - Maximum number of rows (optional)\n * @returns Query result\n *\n * @example\n * ```typescript\n * const blob = await client.getFile('data/sales.parquet');\n * const data = await readParquet(blob, 1000);\n * console.log(`Loaded ${data.rowCount} rows`);\n * ```\n */\nexport async function readParquet(\n blob: Blob,\n limit?: number,\n): Promise<QueryResult> {\n // Generate unique table name to avoid conflicts\n // Note: Math.random() is acceptable here as uniqueness is only needed for table naming (not security-critical)\n /* eslint-disable sonarjs/pseudo-random */\n const uniqueId = `temp_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n /* eslint-enable sonarjs/pseudo-random */\n const reader = new ParquetReader(uniqueId);\n\n await reader.registerParquet(blob);\n\n const result = await reader.getAll(limit);\n\n await reader.close();\n return result;\n}\n","import { OxyConfig, createConfigAsync } from \"./config\";\nimport {\n AppItem,\n AppDataResponse,\n GetDisplaysResponse,\n ApiError,\n TableData,\n} from \"./types\";\nimport { readParquet } from \"./parquet\";\n\n/**\n * Oxy API Client for interacting with Oxy data\n */\nexport class OxyClient {\n private config: OxyConfig;\n\n constructor(config: OxyConfig) {\n this.config = config;\n }\n\n /**\n * Creates an OxyClient instance asynchronously with support for postMessage authentication\n *\n * This is the recommended method when using the SDK in an iframe that needs to\n * obtain authentication from the parent window via postMessage.\n *\n * @param config - Optional configuration overrides\n * @returns Promise resolving to OxyClient instance\n * @throws Error if required configuration is missing\n * @throws PostMessageAuthTimeoutError if parent doesn't respond\n *\n * @example\n * ```typescript\n * // In an iframe - automatic postMessage auth\n * const client = await OxyClient.create({\n * parentOrigin: 'https://app.example.com',\n * projectId: 'my-project-id',\n * baseUrl: 'https://api.oxy.tech'\n * });\n *\n * // Use the client normally\n * const apps = await client.listApps();\n * ```\n */\n static async create(config?: Partial<OxyConfig>): Promise<OxyClient> {\n const resolvedConfig = await createConfigAsync(config);\n return new OxyClient(resolvedConfig);\n }\n\n /**\n * Encodes a file path to base64 for use in API URLs\n */\n private encodePathBase64(path: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(path).toString(\"base64\");\n } else {\n // Browser environment\n return btoa(path);\n }\n }\n\n /**\n * Makes an authenticated HTTP request to the Oxy API\n */\n private async request<T>(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<T> {\n const url = `${this.config.baseUrl}${endpoint}`;\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n ...((options.headers as Record<string, string>) || {}),\n };\n\n // Only add Authorization header if API key is provided (optional for local dev)\n if (this.config.apiKey) {\n headers[\"Authorization\"] = `Bearer ${this.config.apiKey}`;\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n this.config.timeout || 30000,\n );\n\n try {\n const response = await fetch(url, {\n ...options,\n headers,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => \"Unknown error\");\n const error: ApiError = {\n message: `API request failed: ${response.statusText}`,\n status: response.status,\n details: errorText,\n };\n throw error;\n }\n\n // Handle binary responses\n const acceptHeader =\n typeof options.headers === \"object\" && options.headers !== null\n ? (options.headers as Record<string, string>)[\"Accept\"]\n : undefined;\n if (acceptHeader === \"application/octet-stream\") {\n return response.blob() as Promise<T>;\n }\n\n return response.json();\n } catch (error: unknown) {\n clearTimeout(timeoutId);\n\n if (error instanceof Error && error.name === \"AbortError\") {\n throw new Error(\n `Request timeout after ${this.config.timeout || 30000}ms`,\n );\n }\n\n throw error;\n }\n }\n\n /**\n * Builds query parameters including optional branch\n */\n private buildQueryParams(\n additionalParams: Record<string, string> = {},\n ): string {\n const params: Record<string, string> = { ...additionalParams };\n\n if (this.config.branch) {\n params.branch = this.config.branch;\n }\n\n const searchParams = new URLSearchParams(params);\n const queryString = searchParams.toString();\n return queryString ? `?${queryString}` : \"\";\n }\n\n /**\n * Lists all apps in the project\n *\n * @returns Array of app items\n *\n * @example\n * ```typescript\n * const apps = await client.listApps();\n * console.log('Available apps:', apps);\n * ```\n */\n async listApps(): Promise<AppItem[]> {\n const query = this.buildQueryParams();\n return this.request<AppItem[]>(`/${this.config.projectId}/app${query}`);\n }\n\n /**\n * Gets data for a specific app\n *\n * @param appPath - Relative path to the app file (e.g., 'my-app.app.yml')\n * @returns App data response\n *\n * @example\n * ```typescript\n * const data = await client.getAppData('dashboard.app.yml');\n * if (data.error) {\n * console.error('Error:', data.error);\n * } else {\n * console.log('App data:', data.data);\n * }\n * ```\n */\n async getAppData(appPath: string): Promise<AppDataResponse> {\n const pathb64 = this.encodePathBase64(appPath);\n const query = this.buildQueryParams();\n return this.request<AppDataResponse>(\n `/${this.config.projectId}/app/${pathb64}${query}`,\n );\n }\n\n /**\n * Runs an app and returns fresh data (bypasses cache)\n *\n * @param appPath - Relative path to the app file\n * @returns App data response\n *\n * @example\n * ```typescript\n * const data = await client.runApp('dashboard.app.yml');\n * console.log('Fresh app data:', data.data);\n * ```\n */\n async runApp(appPath: string): Promise<AppDataResponse> {\n const pathb64 = this.encodePathBase64(appPath);\n const query = this.buildQueryParams();\n return this.request<AppDataResponse>(\n `/${this.config.projectId}/app/${pathb64}/run${query}`,\n { method: \"POST\" },\n );\n }\n\n /**\n * Gets display configurations for an app\n *\n * @param appPath - Relative path to the app file\n * @returns Display configurations with potential errors\n *\n * @example\n * ```typescript\n * const displays = await client.getDisplays('dashboard.app.yml');\n * displays.displays.forEach(d => {\n * if (d.error) {\n * console.error('Display error:', d.error);\n * } else {\n * console.log('Display:', d.display);\n * }\n * });\n * ```\n */\n async getDisplays(appPath: string): Promise<GetDisplaysResponse> {\n const pathb64 = this.encodePathBase64(appPath);\n const query = this.buildQueryParams();\n return this.request<GetDisplaysResponse>(\n `/${this.config.projectId}/app/${pathb64}/displays${query}`,\n );\n }\n\n /**\n * Gets a file from the app state directory (e.g., generated charts, images)\n *\n * This is useful for retrieving generated assets like charts, images, or other\n * files produced by app workflows and stored in the state directory.\n *\n * @param filePath - Relative path to the file in state directory\n * @returns Blob containing the file data\n *\n * @example\n * ```typescript\n * // Get a generated chart image\n * const blob = await client.getFile('charts/sales-chart.png');\n * const imageUrl = URL.createObjectURL(blob);\n *\n * // Use in an img tag\n * document.querySelector('img').src = imageUrl;\n * ```\n *\n * @example\n * ```typescript\n * // Download a file\n * const blob = await client.getFile('exports/data.csv');\n * const a = document.createElement('a');\n * a.href = URL.createObjectURL(blob);\n * a.download = 'data.csv';\n * a.click();\n * ```\n */\n async getFile(filePath: string): Promise<Blob> {\n const pathb64 = this.encodePathBase64(filePath);\n const query = this.buildQueryParams();\n return this.request<Blob>(\n `/${this.config.projectId}/app/file/${pathb64}${query}`,\n {\n headers: {\n Accept: \"application/octet-stream\",\n },\n },\n );\n }\n\n /**\n * Gets a file URL for direct browser access\n *\n * This returns a URL that can be used directly in img tags, fetch calls, etc.\n * The URL includes authentication via query parameters.\n *\n * @param filePath - Relative path to the file in state directory\n * @returns Full URL to the file\n *\n * @example\n * ```typescript\n * const imageUrl = client.getFileUrl('charts/sales-chart.png');\n *\n * // Use directly in img tag (in environments where query-based auth is supported)\n * document.querySelector('img').src = imageUrl;\n * ```\n */\n getFileUrl(filePath: string): string {\n const pathb64 = this.encodePathBase64(filePath);\n const query = this.buildQueryParams();\n return `${this.config.baseUrl}/${this.config.projectId}/app/file/${pathb64}${query}`;\n }\n\n /**\n * Fetches a parquet file and parses it into table data\n *\n * @param filePath - Relative path to the parquet file\n * @param limit - Maximum number of rows to return (default: 100)\n * @returns TableData with columns and rows\n *\n * @example\n * ```typescript\n * const tableData = await client.getTableData('data/sales.parquet', 50);\n * console.log(tableData.columns);\n * console.log(tableData.rows);\n * console.log(`Total rows: ${tableData.total_rows}`);\n * ```\n */\n async getTableData(\n filePath: string,\n limit: number = 100,\n ): Promise<TableData> {\n const blob = await this.getFile(filePath);\n const result = await readParquet(blob, limit);\n\n return {\n columns: result.columns,\n rows: result.rows,\n total_r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QACV,IAAI,KAAK,OAAO,UAAU,YAAY,UAAU,SAChD,EACE,SAAS,EACP,QAAQ,4BACT,EACF,CACF;;;;;;;;;;;;;;;;;;;CAoBH,WAAW,UAA0B;EACnC,MAAM,UAAU,KAAK,iBAAiB,SAAS;EAC/C,MAAM,QAAQ,KAAK,kBAAkB;AACrC,SAAO,GAAG,KAAK,OAAO,QAAQ,GAAG,KAAK,OAAO,UAAU,YAAY,UAAU;;;;;;;;;;;;;;;;;CAkB/E,MAAM,aACJ,UACA,QAAgB,KACI;EAEpB,MAAM,SAAS,MAAM,YADR,MAAM,KAAK,QAAQ,SAAS,EACF,MAAM;AAE7C,SAAO;GACL,SAAS,OAAO;GAChB,MAAM,OAAO;GACb,YAAY,OAAO;GACpB"}
|
package/dist/index.d.cts
CHANGED
|
@@ -108,7 +108,7 @@ interface FileReference {
|
|
|
108
108
|
*/
|
|
109
109
|
interface TableData {
|
|
110
110
|
columns: string[];
|
|
111
|
-
rows:
|
|
111
|
+
rows: unknown[][];
|
|
112
112
|
total_rows?: number;
|
|
113
113
|
}
|
|
114
114
|
type DataContainer = Record<string, FileReference>;
|
|
@@ -131,7 +131,7 @@ interface DisplayWithError {
|
|
|
131
131
|
*/
|
|
132
132
|
interface DisplayData {
|
|
133
133
|
type: string;
|
|
134
|
-
content:
|
|
134
|
+
content: unknown;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Response from get displays endpoint
|
|
@@ -144,7 +144,7 @@ interface GetDisplaysResponse {
|
|
|
144
144
|
*/
|
|
145
145
|
interface QueryResult$1 {
|
|
146
146
|
columns: string[];
|
|
147
|
-
rows:
|
|
147
|
+
rows: unknown[][];
|
|
148
148
|
rowCount: number;
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
@@ -154,8 +154,8 @@ interface QueryResult$1 {
|
|
|
154
154
|
* Request message sent from iframe to parent window
|
|
155
155
|
*/
|
|
156
156
|
interface OxyAuthRequestMessage {
|
|
157
|
-
type:
|
|
158
|
-
version:
|
|
157
|
+
type: "OXY_AUTH_REQUEST";
|
|
158
|
+
version: "1.0";
|
|
159
159
|
timestamp: number;
|
|
160
160
|
requestId: string;
|
|
161
161
|
}
|
|
@@ -163,8 +163,8 @@ interface OxyAuthRequestMessage {
|
|
|
163
163
|
* Response message sent from parent window to iframe
|
|
164
164
|
*/
|
|
165
165
|
interface OxyAuthResponseMessage {
|
|
166
|
-
type:
|
|
167
|
-
version:
|
|
166
|
+
type: "OXY_AUTH_RESPONSE";
|
|
167
|
+
version: "1.0";
|
|
168
168
|
requestId: string;
|
|
169
169
|
apiKey?: string;
|
|
170
170
|
projectId?: string;
|
|
@@ -188,7 +188,7 @@ interface PostMessageAuthResult {
|
|
|
188
188
|
apiKey?: string;
|
|
189
189
|
projectId?: string;
|
|
190
190
|
baseUrl?: string;
|
|
191
|
-
source:
|
|
191
|
+
source: "postmessage";
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
194
194
|
* Custom error classes for postMessage authentication
|
|
@@ -399,7 +399,7 @@ declare function initializeDuckDB(): Promise<duckdb.AsyncDuckDB>;
|
|
|
399
399
|
*/
|
|
400
400
|
interface QueryResult {
|
|
401
401
|
columns: string[];
|
|
402
|
-
rows:
|
|
402
|
+
rows: unknown[][];
|
|
403
403
|
rowCount: number;
|
|
404
404
|
}
|
|
405
405
|
/**
|
|
@@ -407,6 +407,7 @@ interface QueryResult {
|
|
|
407
407
|
*/
|
|
408
408
|
declare class ParquetReader {
|
|
409
409
|
private tableName;
|
|
410
|
+
private internalTableName;
|
|
410
411
|
private registered;
|
|
411
412
|
constructor(tableName?: string);
|
|
412
413
|
/**
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/config.ts","../src/types.ts","../src/client.ts","../src/parquet.ts","../src/auth/postMessage.ts"],"sourcesContent":[],"mappings":";;;;;;;AAGiB,UAAA,SAAA,CAAS;EAsDV;;;EAA8C,OAAA,EAAA,MAAA;EAAS;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/config.ts","../src/types.ts","../src/client.ts","../src/parquet.ts","../src/auth/postMessage.ts"],"sourcesContent":[],"mappings":";;;;;;;AAGiB,UAAA,SAAA,CAAS;EAsDV;;;EAA8C,OAAA,EAAA,MAAA;EAAS;AA6DvE;;EACc,MAAA,CAAA,EAAA,MAAA;EACH;;;;;;ACrHX;EAQiB,MAAA,CAAA,EAAA,MAAA;EAQA;AAMjB;AAKA;EAQiB,OAAA,CAAA,EAAA,MAAA;EAQA;AAQjB;AAgBA;AAaA;AAUA;AAYA;EAYiB,YAAA,CAAA,EAAA,MAAA;EAcJ;AAoBb;AAeA;AA0BA;;;;ACnLA;;;;;;;;;;;;AAoN8C,iBFxK9B,YAAA,CEwK8B,SAAA,CAAA,EFxKL,OEwKK,CFxKG,SEwKH,CAAA,CAAA,EFxKgB,SEwKhB;;;;;;;;;;ACtM9C;AA0CA;AASA;;;;;;;;;;;;AA4MA;;;;;AAkCA;;;;;iBHtMsB,iBAAA,aACR,QAAQ,aACnB,QAAQ;;;;;;AArHM,UCAA,OAAA,CDAS;EAsDV,IAAA,EAAA,MAAA;EAAiC,IAAA,EAAA,MAAA;;;;AA6DjD;AACsB,UC5GL,aAAA,CD4GK;EAAR,SAAA,EAAA,MAAA;;;;;;UCpGG,SAAA;EAhBA,OAAA,EAAA,MAAO,EAAA;EAQP,IAAA,EAAA,OAAA,EAAA,EAAa;EAQb,UAAA,CAAA,EAAS,MAAA;AAM1B;AAKiB,KALL,aAAA,GAAgB,MAMpB,CAAA,MAAA,EANmC,aAMtB,CAAA;AAOrB;AAQA;AAQA;AAgBiB,UAxCA,eAAA,CAwCW;EAaX,IAAA,EApDT,aAoDS,GAAA,IAAqB;EAUrB,KAAA,EAAA,MAAA,GAAA,IAAA;AAYjB;AAYA;AAcA;AAoBA;AAea,UAhII,gBAAA,CAgIJ;EA0BA,OAAA,CAAA,EAzJD,WAyJC;;;;ACnLb;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