juxscript 1.1.401 → 1.1.402

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.
@@ -0,0 +1,64 @@
1
+ import type { ApiGateway } from '../components/gateway.js';
2
+ export interface RdsServiceOptions {
3
+ serverUrl?: string;
4
+ apiKey?: string;
5
+ gateway?: ApiGateway;
6
+ }
7
+ /**
8
+ * Standalone client for the jux-server rds-service (Amazon RDS / Aurora / PostgreSQL / MySQL).
9
+ * Can authenticate via a live ApiGateway session (JWT) or a static API key.
10
+ */
11
+ export declare class RdsService {
12
+ id: string;
13
+ options: RdsServiceOptions;
14
+ private _value;
15
+ private _loading;
16
+ private _error;
17
+ constructor(id: string, options?: RdsServiceOptions);
18
+ serverUrl(value: string): this;
19
+ apiKey(value: string): this;
20
+ setServerUrl(value: string): void;
21
+ getServerUrl(): string | undefined;
22
+ setApiKey(value: string): void;
23
+ getApiKey(): string | undefined;
24
+ getValue(): any;
25
+ getLoading(): boolean;
26
+ getError(): string | null;
27
+ /** Returns the reactive pageState proxy for this service. */
28
+ get state(): any;
29
+ private _request;
30
+ /**
31
+ * Run a SELECT query against Amazon RDS.
32
+ * @example
33
+ * const rows = await rds.query('SELECT * FROM orders WHERE status = :status', { status: 'open' });
34
+ */
35
+ query(sql: string, params?: any[] | Record<string, any>): Promise<any>;
36
+ /**
37
+ * Run a write statement (INSERT / UPDATE / DELETE / DDL) against Amazon RDS.
38
+ * @example
39
+ * await rds.execute('UPDATE orders SET status = :status WHERE id = :id', { status: 'closed', id: 42 });
40
+ */
41
+ execute(sql: string, params?: any[] | Record<string, any>): Promise<any>;
42
+ }
43
+ /**
44
+ * Create a client for the jux-server rds-service (Amazon RDS / Aurora).
45
+ *
46
+ * Authenticate via an existing `ApiGateway` session or with a static API key.
47
+ *
48
+ * @example
49
+ * // Via gateway (JWT)
50
+ * const gw = await jux.gateway('auth', { serverUrl: 'https://api.example.com' });
51
+ * await gw.login('alice@example.com', 'p4ssw0rd');
52
+ * const rds = await jux.rdsService('rds', { gateway: gw });
53
+ *
54
+ * // Via API key
55
+ * const rds = await jux.rdsService('rds', {
56
+ * serverUrl: 'https://api.example.com',
57
+ * apiKey: 'my-api-key',
58
+ * });
59
+ *
60
+ * const rows = await rds.query('SELECT * FROM products WHERE active = true');
61
+ * await rds.execute('DELETE FROM sessions WHERE expires_at < NOW()');
62
+ */
63
+ export declare function rdsService(id: string, options?: RdsServiceOptions): Promise<RdsService>;
64
+ //# sourceMappingURL=rdsService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rdsService.d.ts","sourceRoot":"","sources":["../../lib/services/rdsService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,UAAU,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,UAAU;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,iBAAiB,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,MAAM,CAAuB;gBAEzB,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAQvD,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC9B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IACjC,YAAY,IAAI,MAAM,GAAG,SAAS;IAClC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC9B,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B,QAAQ,IAAI,GAAG;IACf,UAAU,IAAI,OAAO;IACrB,QAAQ,IAAI,MAAM,GAAG,IAAI;IAEzB,6DAA6D;IAC7D,IAAI,KAAK,IAAI,GAAG,CAA+B;YAIjC,QAAQ;IAyBtB;;;;OAIG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAoBhF;;;;OAIG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAmBrF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CAIjG"}
@@ -0,0 +1,130 @@
1
+ import generateId from '../utils/idgen.js';
2
+ import { pageState } from '../state/pageState.js';
3
+ /**
4
+ * Standalone client for the jux-server rds-service (Amazon RDS / Aurora / PostgreSQL / MySQL).
5
+ * Can authenticate via a live ApiGateway session (JWT) or a static API key.
6
+ */
7
+ export class RdsService {
8
+ constructor(id, options = {}) {
9
+ this._value = null;
10
+ this._loading = false;
11
+ this._error = null;
12
+ this.id = id || generateId();
13
+ const configUrl = (typeof window !== 'undefined' && window.juxConfig?.proxy?.url) || '';
14
+ this.options = { serverUrl: configUrl, ...options };
15
+ }
16
+ // ── Fluent setters ──
17
+ serverUrl(value) { this.options.serverUrl = value; return this; }
18
+ apiKey(value) { this.options.apiKey = value; return this; }
19
+ // ── Setters / getters (for pageState delegation) ──
20
+ setServerUrl(value) { this.options.serverUrl = value; }
21
+ getServerUrl() { return this.options.serverUrl; }
22
+ setApiKey(value) { this.options.apiKey = value; }
23
+ getApiKey() { return this.options.apiKey; }
24
+ // ── State accessors ──
25
+ getValue() { return this._value; }
26
+ getLoading() { return this._loading; }
27
+ getError() { return this._error; }
28
+ /** Returns the reactive pageState proxy for this service. */
29
+ get state() { return pageState[this.id]; }
30
+ // ── Internal HTTP ──
31
+ async _request(path, method = 'POST', body) {
32
+ if (this.options.gateway) {
33
+ return this.options.gateway._request(path, method, body);
34
+ }
35
+ const base = this.options.serverUrl || '';
36
+ const url = `${base}${path}`;
37
+ const headers = { 'Content-Type': 'application/json' };
38
+ if (this.options.apiKey) {
39
+ headers['X-Api-Key'] = this.options.apiKey;
40
+ }
41
+ const init = { method, headers };
42
+ if (body !== undefined) {
43
+ init.body = JSON.stringify(body);
44
+ }
45
+ const res = await globalThis.fetch(url, init);
46
+ const ct = res.headers.get('content-type') || '';
47
+ const data = ct.includes('application/json') ? await res.json() : await res.text();
48
+ if (!res.ok) {
49
+ throw new Error(data?.message || data?.error || `HTTP ${res.status}`);
50
+ }
51
+ return data;
52
+ }
53
+ // ── rds-service operations ──
54
+ /**
55
+ * Run a SELECT query against Amazon RDS.
56
+ * @example
57
+ * const rows = await rds.query('SELECT * FROM orders WHERE status = :status', { status: 'open' });
58
+ */
59
+ async query(sql, params = []) {
60
+ this._loading = true;
61
+ this._error = null;
62
+ pageState.__notify(`${this.id}.loading`);
63
+ try {
64
+ this._value = await this._request('/proxy/rds/', 'POST', { action: 'query', sql, params });
65
+ this._loading = false;
66
+ pageState.__notify(`${this.id}.value`);
67
+ pageState.__notify(`${this.id}.loading`);
68
+ return this._value;
69
+ }
70
+ catch (err) {
71
+ this._loading = false;
72
+ this._error = err.message || 'Query failed';
73
+ console.error(`❌ jux.rdsService('${this.id}') query error:`, err.message);
74
+ pageState.__notify(`${this.id}.error`);
75
+ pageState.__notify(`${this.id}.loading`);
76
+ throw err;
77
+ }
78
+ }
79
+ /**
80
+ * Run a write statement (INSERT / UPDATE / DELETE / DDL) against Amazon RDS.
81
+ * @example
82
+ * await rds.execute('UPDATE orders SET status = :status WHERE id = :id', { status: 'closed', id: 42 });
83
+ */
84
+ async execute(sql, params = []) {
85
+ this._loading = true;
86
+ this._error = null;
87
+ pageState.__notify(`${this.id}.loading`);
88
+ try {
89
+ this._value = await this._request('/proxy/rds/', 'POST', { action: 'execute', sql, params });
90
+ this._loading = false;
91
+ pageState.__notify(`${this.id}.value`);
92
+ pageState.__notify(`${this.id}.loading`);
93
+ return this._value;
94
+ }
95
+ catch (err) {
96
+ this._loading = false;
97
+ this._error = err.message || 'Execute failed';
98
+ console.error(`❌ jux.rdsService('${this.id}') execute error:`, err.message);
99
+ pageState.__notify(`${this.id}.error`);
100
+ pageState.__notify(`${this.id}.loading`);
101
+ throw err;
102
+ }
103
+ }
104
+ }
105
+ /**
106
+ * Create a client for the jux-server rds-service (Amazon RDS / Aurora).
107
+ *
108
+ * Authenticate via an existing `ApiGateway` session or with a static API key.
109
+ *
110
+ * @example
111
+ * // Via gateway (JWT)
112
+ * const gw = await jux.gateway('auth', { serverUrl: 'https://api.example.com' });
113
+ * await gw.login('alice@example.com', 'p4ssw0rd');
114
+ * const rds = await jux.rdsService('rds', { gateway: gw });
115
+ *
116
+ * // Via API key
117
+ * const rds = await jux.rdsService('rds', {
118
+ * serverUrl: 'https://api.example.com',
119
+ * apiKey: 'my-api-key',
120
+ * });
121
+ *
122
+ * const rows = await rds.query('SELECT * FROM products WHERE active = true');
123
+ * await rds.execute('DELETE FROM sessions WHERE expires_at < NOW()');
124
+ */
125
+ export async function rdsService(id, options = {}) {
126
+ const s = new RdsService(id, options);
127
+ pageState.__register(s);
128
+ return s;
129
+ }
130
+ //# sourceMappingURL=rdsService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rdsService.js","sourceRoot":"","sources":["../../lib/services/rdsService.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AASlD;;;GAGG;AACH,MAAM,OAAO,UAAU;IAOnB,YAAY,EAAU,EAAE,UAA6B,EAAE;QAJ/C,WAAM,GAAQ,IAAI,CAAC;QACnB,aAAQ,GAAY,KAAK,CAAC;QAC1B,WAAM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C,CAAC;IACxB,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,84 @@
1
+ import type { ApiGateway } from '../components/gateway.js';
2
+ export interface StorageServiceOptions {
3
+ serverUrl?: string;
4
+ apiKey?: string;
5
+ gateway?: ApiGateway;
6
+ }
7
+ /**
8
+ * Standalone client for the jux-server storage-service (Amazon S3).
9
+ * Can authenticate via a live ApiGateway session (JWT) or a static API key.
10
+ */
11
+ export declare class StorageService {
12
+ id: string;
13
+ options: StorageServiceOptions;
14
+ private _value;
15
+ private _loading;
16
+ private _error;
17
+ constructor(id: string, options?: StorageServiceOptions);
18
+ serverUrl(value: string): this;
19
+ apiKey(value: string): this;
20
+ setServerUrl(value: string): void;
21
+ getServerUrl(): string | undefined;
22
+ setApiKey(value: string): void;
23
+ getApiKey(): string | undefined;
24
+ getValue(): any;
25
+ getLoading(): boolean;
26
+ getError(): string | null;
27
+ /** Returns the reactive pageState proxy for this service. */
28
+ get state(): any;
29
+ private _request;
30
+ /**
31
+ * Upload an object to S3.
32
+ * @param key - Object key (path) in the bucket, e.g. `'avatars/alice.jpg'`
33
+ * @param data - The file data to upload
34
+ * @param contentType - MIME type, defaults to `'application/octet-stream'`
35
+ * @example
36
+ * await storage.upload('reports/2024.pdf', pdfBlob, 'application/pdf');
37
+ */
38
+ upload(key: string, data: any, contentType?: string): Promise<any>;
39
+ /**
40
+ * Download an object from S3 (returns a pre-signed URL or the object data).
41
+ * @param key - Object key (path) in the bucket
42
+ * @example
43
+ * const { url } = await storage.download('avatars/alice.jpg');
44
+ */
45
+ download(key: string): Promise<any>;
46
+ /**
47
+ * List objects in S3 under a given prefix.
48
+ * @param prefix - Key prefix to filter by, e.g. `'avatars/'`
49
+ * @example
50
+ * const { objects } = await storage.list('uploads/');
51
+ */
52
+ list(prefix?: string): Promise<any>;
53
+ /**
54
+ * Delete an object from S3.
55
+ * @param key - Object key (path) to delete
56
+ * @example
57
+ * await storage.deleteFile('avatars/old-avatar.jpg');
58
+ */
59
+ deleteFile(key: string): Promise<any>;
60
+ }
61
+ /**
62
+ * Create a client for the jux-server storage-service (Amazon S3).
63
+ *
64
+ * Authenticate via an existing `ApiGateway` session or with a static API key.
65
+ *
66
+ * @example
67
+ * // Via gateway (JWT)
68
+ * const gw = await jux.gateway('auth', { serverUrl: 'https://api.example.com' });
69
+ * await gw.login('alice@example.com', 'p4ssw0rd');
70
+ * const storage = await jux.storageService('storage', { gateway: gw });
71
+ *
72
+ * // Via API key
73
+ * const storage = await jux.storageService('storage', {
74
+ * serverUrl: 'https://api.example.com',
75
+ * apiKey: 'my-api-key',
76
+ * });
77
+ *
78
+ * await storage.upload('avatars/alice.jpg', fileBlob, 'image/jpeg');
79
+ * const { url } = await storage.download('avatars/alice.jpg');
80
+ * const { objects } = await storage.list('avatars/');
81
+ * await storage.deleteFile('avatars/old.jpg');
82
+ */
83
+ export declare function storageService(id: string, options?: StorageServiceOptions): Promise<StorageService>;
84
+ //# sourceMappingURL=storageService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storageService.d.ts","sourceRoot":"","sources":["../../lib/services/storageService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,WAAW,qBAAqB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,UAAU,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,cAAc;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,qBAAqB,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,MAAM,CAAuB;gBAEzB,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;IAQ3D,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC9B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IACjC,YAAY,IAAI,MAAM,GAAG,SAAS;IAClC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC9B,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B,QAAQ,IAAI,GAAG;IACf,UAAU,IAAI,OAAO;IACrB,QAAQ,IAAI,MAAM,GAAG,IAAI;IAEzB,6DAA6D;IAC7D,IAAI,KAAK,IAAI,GAAG,CAA+B;YAIjC,QAAQ;IAyBtB;;;;;;;OAOG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,SAA6B,GAAG,OAAO,CAAC,GAAG,CAAC;IAoB5F;;;;;OAKG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAoBzC;;;;;OAKG;IACG,IAAI,CAAC,MAAM,SAAK,GAAG,OAAO,CAAC,GAAG,CAAC;IAuBrC;;;;;OAKG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAmB9C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,cAAc,CAAC,CAI7G"}
@@ -0,0 +1,188 @@
1
+ import generateId from '../utils/idgen.js';
2
+ import { pageState } from '../state/pageState.js';
3
+ /**
4
+ * Standalone client for the jux-server storage-service (Amazon S3).
5
+ * Can authenticate via a live ApiGateway session (JWT) or a static API key.
6
+ */
7
+ export class StorageService {
8
+ constructor(id, options = {}) {
9
+ this._value = null;
10
+ this._loading = false;
11
+ this._error = null;
12
+ this.id = id || generateId();
13
+ const configUrl = (typeof window !== 'undefined' && window.juxConfig?.proxy?.url) || '';
14
+ this.options = { serverUrl: configUrl, ...options };
15
+ }
16
+ // ── Fluent setters ──
17
+ serverUrl(value) { this.options.serverUrl = value; return this; }
18
+ apiKey(value) { this.options.apiKey = value; return this; }
19
+ // ── Setters / getters (for pageState delegation) ──
20
+ setServerUrl(value) { this.options.serverUrl = value; }
21
+ getServerUrl() { return this.options.serverUrl; }
22
+ setApiKey(value) { this.options.apiKey = value; }
23
+ getApiKey() { return this.options.apiKey; }
24
+ // ── State accessors ──
25
+ getValue() { return this._value; }
26
+ getLoading() { return this._loading; }
27
+ getError() { return this._error; }
28
+ /** Returns the reactive pageState proxy for this service. */
29
+ get state() { return pageState[this.id]; }
30
+ // ── Internal HTTP ──
31
+ async _request(path, method = 'GET', body) {
32
+ if (this.options.gateway) {
33
+ return this.options.gateway._request(path, method, body);
34
+ }
35
+ const base = this.options.serverUrl || '';
36
+ const url = `${base}${path}`;
37
+ const headers = { 'Content-Type': 'application/json' };
38
+ if (this.options.apiKey) {
39
+ headers['X-Api-Key'] = this.options.apiKey;
40
+ }
41
+ const init = { method, headers };
42
+ if (body !== undefined) {
43
+ init.body = JSON.stringify(body);
44
+ }
45
+ const res = await globalThis.fetch(url, init);
46
+ const ct = res.headers.get('content-type') || '';
47
+ const data = ct.includes('application/json') ? await res.json() : await res.text();
48
+ if (!res.ok) {
49
+ throw new Error(data?.message || data?.error || `HTTP ${res.status}`);
50
+ }
51
+ return data;
52
+ }
53
+ // ── storage-service operations ──
54
+ /**
55
+ * Upload an object to S3.
56
+ * @param key - Object key (path) in the bucket, e.g. `'avatars/alice.jpg'`
57
+ * @param data - The file data to upload
58
+ * @param contentType - MIME type, defaults to `'application/octet-stream'`
59
+ * @example
60
+ * await storage.upload('reports/2024.pdf', pdfBlob, 'application/pdf');
61
+ */
62
+ async upload(key, data, contentType = 'application/octet-stream') {
63
+ this._loading = true;
64
+ this._error = null;
65
+ pageState.__notify(`${this.id}.loading`);
66
+ try {
67
+ this._value = await this._request(`/proxy/storage/${key}`, 'PUT', { data, contentType });
68
+ this._loading = false;
69
+ pageState.__notify(`${this.id}.value`);
70
+ pageState.__notify(`${this.id}.loading`);
71
+ return this._value;
72
+ }
73
+ catch (err) {
74
+ this._loading = false;
75
+ this._error = err.message || 'Upload failed';
76
+ console.error(`❌ jux.storageService('${this.id}') upload error:`, err.message);
77
+ pageState.__notify(`${this.id}.error`);
78
+ pageState.__notify(`${this.id}.loading`);
79
+ throw err;
80
+ }
81
+ }
82
+ /**
83
+ * Download an object from S3 (returns a pre-signed URL or the object data).
84
+ * @param key - Object key (path) in the bucket
85
+ * @example
86
+ * const { url } = await storage.download('avatars/alice.jpg');
87
+ */
88
+ async download(key) {
89
+ this._loading = true;
90
+ this._error = null;
91
+ pageState.__notify(`${this.id}.loading`);
92
+ try {
93
+ this._value = await this._request(`/proxy/storage/${key}`, 'GET');
94
+ this._loading = false;
95
+ pageState.__notify(`${this.id}.value`);
96
+ pageState.__notify(`${this.id}.loading`);
97
+ return this._value;
98
+ }
99
+ catch (err) {
100
+ this._loading = false;
101
+ this._error = err.message || 'Download failed';
102
+ console.error(`❌ jux.storageService('${this.id}') download error:`, err.message);
103
+ pageState.__notify(`${this.id}.error`);
104
+ pageState.__notify(`${this.id}.loading`);
105
+ throw err;
106
+ }
107
+ }
108
+ /**
109
+ * List objects in S3 under a given prefix.
110
+ * @param prefix - Key prefix to filter by, e.g. `'avatars/'`
111
+ * @example
112
+ * const { objects } = await storage.list('uploads/');
113
+ */
114
+ async list(prefix = '') {
115
+ this._loading = true;
116
+ this._error = null;
117
+ pageState.__notify(`${this.id}.loading`);
118
+ try {
119
+ this._value = await this._request(`/proxy/storage/?prefix=${encodeURIComponent(prefix)}`, 'GET');
120
+ this._loading = false;
121
+ pageState.__notify(`${this.id}.value`);
122
+ pageState.__notify(`${this.id}.loading`);
123
+ return this._value;
124
+ }
125
+ catch (err) {
126
+ this._loading = false;
127
+ this._error = err.message || 'List failed';
128
+ console.error(`❌ jux.storageService('${this.id}') list error:`, err.message);
129
+ pageState.__notify(`${this.id}.error`);
130
+ pageState.__notify(`${this.id}.loading`);
131
+ throw err;
132
+ }
133
+ }
134
+ /**
135
+ * Delete an object from S3.
136
+ * @param key - Object key (path) to delete
137
+ * @example
138
+ * await storage.deleteFile('avatars/old-avatar.jpg');
139
+ */
140
+ async deleteFile(key) {
141
+ this._loading = true;
142
+ this._error = null;
143
+ pageState.__notify(`${this.id}.loading`);
144
+ try {
145
+ this._value = await this._request(`/proxy/storage/${key}`, 'DELETE');
146
+ this._loading = false;
147
+ pageState.__notify(`${this.id}.value`);
148
+ pageState.__notify(`${this.id}.loading`);
149
+ return this._value;
150
+ }
151
+ catch (err) {
152
+ this._loading = false;
153
+ this._error = err.message || 'Delete failed';
154
+ console.error(`❌ jux.storageService('${this.id}') deleteFile error:`, err.message);
155
+ pageState.__notify(`${this.id}.error`);
156
+ pageState.__notify(`${this.id}.loading`);
157
+ throw err;
158
+ }
159
+ }
160
+ }
161
+ /**
162
+ * Create a client for the jux-server storage-service (Amazon S3).
163
+ *
164
+ * Authenticate via an existing `ApiGateway` session or with a static API key.
165
+ *
166
+ * @example
167
+ * // Via gateway (JWT)
168
+ * const gw = await jux.gateway('auth', { serverUrl: 'https://api.example.com' });
169
+ * await gw.login('alice@example.com', 'p4ssw0rd');
170
+ * const storage = await jux.storageService('storage', { gateway: gw });
171
+ *
172
+ * // Via API key
173
+ * const storage = await jux.storageService('storage', {
174
+ * serverUrl: 'https://api.example.com',
175
+ * apiKey: 'my-api-key',
176
+ * });
177
+ *
178
+ * await storage.upload('avatars/alice.jpg', fileBlob, 'image/jpeg');
179
+ * const { url } = await storage.download('avatars/alice.jpg');
180
+ * const { objects } = await storage.list('avatars/');
181
+ * await storage.deleteFile('avatars/old.jpg');
182
+ */
183
+ export async function storageService(id, options = {}) {
184
+ const s = new StorageService(id, options);
185
+ pageState.__register(s);
186
+ return s;
187
+ }
188
+ //# sourceMappingURL=storageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storageService.js","sourceRoot":"","sources":["../../lib/services/storageService.ts"],"names":[],"mappings":"AAAA,OAA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IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;YACrE,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;YACvC,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC,MAAM,CAAC;QACvB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,eAAe,CAAC;YAC7C,OAAO,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,EAAE,sBAAsB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YACnF,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;YACvC,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;YACzC,MAAM,GAAG,CAAC;QACd,CAAC;IACL,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAU,EAAE,UAAiC,EAAE;IAChF,MAAM,CAAC,GAAG,IAAI,cAAc,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC1C,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACxB,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,94 @@
1
+ interface CanvasItem {
2
+ id: string;
3
+ type: string;
4
+ category: 'shapes' | 'widgets' | 'components';
5
+ label: string;
6
+ x: number;
7
+ y: number;
8
+ code: string;
9
+ }
10
+ interface InventoryEntry {
11
+ type: string;
12
+ label: string;
13
+ category: 'shapes' | 'widgets' | 'components';
14
+ }
15
+ interface CanvasOptions {
16
+ title?: string;
17
+ width?: string;
18
+ height?: string;
19
+ inventoryWidth?: string;
20
+ propertiesWidth?: string;
21
+ class?: string;
22
+ style?: string;
23
+ target?: string;
24
+ }
25
+ declare class Canvas {
26
+ id: string;
27
+ private _opts;
28
+ private _el;
29
+ private _items;
30
+ private _selectedId;
31
+ private _activeTab;
32
+ private _onChange;
33
+ private _canvasEl;
34
+ private _inventoryEl;
35
+ private _propertiesEl;
36
+ private _counter;
37
+ constructor(id: string, options?: CanvasOptions);
38
+ title(val: string): this;
39
+ width(val: string): this;
40
+ height(val: string): this;
41
+ inventoryWidth(val: string): this;
42
+ propertiesWidth(val: string): this;
43
+ style(val: string): this;
44
+ class(val: string): this;
45
+ onChange(fn: (value: any) => void): this;
46
+ getValue(): string | null;
47
+ setValue(val: string): this;
48
+ getElement(): HTMLElement | null;
49
+ getTitle(): string;
50
+ getWidth(): string;
51
+ getHeight(): string;
52
+ getInventoryWidth(): string;
53
+ getPropertiesWidth(): string;
54
+ getClass(): string;
55
+ getStyle(): string;
56
+ getItems(): CanvasItem[];
57
+ getSelectedItem(): CanvasItem | null;
58
+ setTitle(val: string): this;
59
+ setWidth(val: string): this;
60
+ setHeight(val: string): this;
61
+ setInventoryWidth(val: string): this;
62
+ setPropertiesWidth(val: string): this;
63
+ setClass(val: string): this;
64
+ setStyle(val: string): this;
65
+ get state(): any;
66
+ addItemToCanvas(type: string, category: 'shapes' | 'widgets' | 'components', x?: number, y?: number): this;
67
+ removeItemFromCanvas(itemId: string): this;
68
+ updateItemCode(itemId: string, code: string): this;
69
+ render(target?: string | HTMLElement | {
70
+ element: HTMLElement;
71
+ }): this;
72
+ into(target?: string | HTMLElement | {
73
+ element: HTMLElement;
74
+ }): this;
75
+ destroy(): void;
76
+ private _buildDOM;
77
+ private _buildInventoryPanel;
78
+ private _buildPropertiesPanel;
79
+ private _renderCanvasItems;
80
+ private _selectItem;
81
+ private _renderProperties;
82
+ private _renderDesignTab;
83
+ private _renderCodeTab;
84
+ private _renderStateTab;
85
+ private _getPropertiesForType;
86
+ private _updatePropertyInCode;
87
+ private _generateFullCode;
88
+ private _generateInteractionExample;
89
+ private _injectStyles;
90
+ }
91
+ export declare function canvas(id: string, options?: CanvasOptions): Canvas;
92
+ export { Canvas, CanvasOptions, CanvasItem, InventoryEntry };
93
+ export default canvas;
94
+ //# sourceMappingURL=canvas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../lib/widgets/canvas.ts"],"names":[],"mappings":"AAOA,UAAU,UAAU;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,cAAc;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC;CACjD;AAED,UAAU,aAAa;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AA0ED,cAAM,MAAM;IACR,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,KAAK,CAAqH;IAClI,OAAO,CAAC,GAAG,CAA4B;IACvC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,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