@proappstore/sdk 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/db.d.ts +24 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +14 -0
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/storage.d.ts +37 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +98 -0
- package/dist/storage.js.map +1 -0
- package/package.json +1 -1
package/dist/db.d.ts
CHANGED
|
@@ -16,6 +16,18 @@ export interface ExecuteResult {
|
|
|
16
16
|
last_row_id: number;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
export interface Migration {
|
|
20
|
+
/** Unique name, e.g. "0001_init" or "0002_add_photos". Run in array order. */
|
|
21
|
+
name: string;
|
|
22
|
+
/** SQL statements separated by semicolons. */
|
|
23
|
+
sql: string;
|
|
24
|
+
}
|
|
25
|
+
export interface MigrateResult {
|
|
26
|
+
/** Migrations that were applied this call. */
|
|
27
|
+
applied: string[];
|
|
28
|
+
/** Migrations that were already applied previously. */
|
|
29
|
+
already: string[];
|
|
30
|
+
}
|
|
19
31
|
export declare class Database {
|
|
20
32
|
private readonly appId;
|
|
21
33
|
private readonly dataApiBase;
|
|
@@ -36,6 +48,18 @@ export declare class Database {
|
|
|
36
48
|
last_row_id: number;
|
|
37
49
|
};
|
|
38
50
|
}[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Run named migrations. Each migration runs once — the data-worker tracks
|
|
53
|
+
* which have been applied in a `_migrations` table. Idempotent: safe to
|
|
54
|
+
* call on every app load.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* await app.db.migrate([
|
|
58
|
+
* { name: '0001_init', sql: 'CREATE TABLE events (id TEXT PRIMARY KEY, ...)' },
|
|
59
|
+
* { name: '0002_photos', sql: 'ALTER TABLE events ADD COLUMN photo_url TEXT' },
|
|
60
|
+
* ])
|
|
61
|
+
*/
|
|
62
|
+
migrate(migrations: Migration[]): Promise<MigrateResult>;
|
|
39
63
|
/** List all user-created tables in the database. */
|
|
40
64
|
tables(): Promise<string[]>;
|
|
41
65
|
private req;
|
package/dist/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kBAAkB,IAAI,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtD,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE;AAED,qBAAa,QAAQ;IAEjB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFJ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,QAAQ;IAGjC,qDAAqD;IAC/C,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIlG,uDAAuD;IACjD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MA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AAa,QAAQ;IAEjB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFJ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,QAAQ;IAGjC,qDAAqD;IAC/C,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIlG,uDAAuD;IACjD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAItE,oEAAoE;IAC9D,KAAK,CAAC,UAAU,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QAAC,IAAI,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,EAAE,CAAC;IAK9I;;;;;;;;;;OAUG;IACG,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAI9D,oDAAoD;IAC9C,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAcnB,GAAG;CAqBlB"}
|
package/dist/db.js
CHANGED
|
@@ -20,6 +20,20 @@ export class Database {
|
|
|
20
20
|
const result = await this.req('/batch', { statements });
|
|
21
21
|
return result.results;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Run named migrations. Each migration runs once — the data-worker tracks
|
|
25
|
+
* which have been applied in a `_migrations` table. Idempotent: safe to
|
|
26
|
+
* call on every app load.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* await app.db.migrate([
|
|
30
|
+
* { name: '0001_init', sql: 'CREATE TABLE events (id TEXT PRIMARY KEY, ...)' },
|
|
31
|
+
* { name: '0002_photos', sql: 'ALTER TABLE events ADD COLUMN photo_url TEXT' },
|
|
32
|
+
* ])
|
|
33
|
+
*/
|
|
34
|
+
async migrate(migrations) {
|
|
35
|
+
return this.req('/migrate', { migrations });
|
|
36
|
+
}
|
|
23
37
|
/** List all user-created tables in the database. */
|
|
24
38
|
async tables() {
|
|
25
39
|
const token = this.auth.token;
|
package/dist/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AA4BA,MAAM,OAAO,QAAQ;IAEA;IACA;IACA;IAHnB,YACmB,KAAa,EACb,WAAmB,EACnB,IAAc;QAFd,UAAK,GAAL,KAAK,CAAQ;QACb,gBAAW,GAAX,WAAW,CAAQ;QACnB,SAAI,GAAJ,IAAI,CAAU;IAC9B,CAAC;IAEJ,qDAAqD;IACrD,KAAK,CAAC,KAAK,CAA8B,GAAW,EAAE,MAAkB;QACtE,OAAO,IAAI,CAAC,GAAG,CAAiB,QAAQ,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,uDAAuD;IACvD,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,MAAkB;QAC3C,OAAO,IAAI,CAAC,GAAG,CAAgB,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,KAAK,CAAC,UAAiD;QAC3D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAqF,QAAQ,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAC5I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EAAE;gBAChC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;QACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,YAAY,QAAQ,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;IACtC,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { FreeAppStore } from '@freeappstore/sdk';
|
|
2
2
|
import { Database } from './db.js';
|
|
3
|
+
import { Storage } from './storage.js';
|
|
3
4
|
import { SubscriptionApi } from './subscription.js';
|
|
4
5
|
import { LicenseApi } from './license.js';
|
|
5
6
|
import type { ProInitOptions } from './types.js';
|
|
6
7
|
export type { User, Unsubscribe, FasInitOptions, ConnectionState, Room, RoomMessage, RoomPeer, } from '@freeappstore/sdk';
|
|
7
8
|
export type { ProInitOptions, Subscription, SubscriptionStatus, CheckoutRequest, LicenseInfo, } from './types.js';
|
|
8
|
-
export type { QueryResult, ExecuteResult } from './db.js';
|
|
9
|
+
export type { QueryResult, ExecuteResult, Migration, MigrateResult } from './db.js';
|
|
9
10
|
/**
|
|
10
11
|
* Pro SDK instance — includes everything from @freeappstore/sdk (auth, kv,
|
|
11
12
|
* counters, rooms, proxy) plus subscription management and license keys.
|
|
@@ -16,6 +17,7 @@ export declare class ProAppStore extends FreeAppStore {
|
|
|
16
17
|
readonly subscription: SubscriptionApi;
|
|
17
18
|
readonly license: LicenseApi;
|
|
18
19
|
readonly db: Database;
|
|
20
|
+
readonly storage: Storage;
|
|
19
21
|
constructor(opts: ProInitOptions);
|
|
20
22
|
}
|
|
21
23
|
/** Create a new ProAppStore SDK instance. Includes all free + pro features. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,YAAY,EACV,IAAI,EACJ,WAAW,EACX,cAAc,EACd,eAAe,EACf,IAAI,EACJ,WAAW,EACX,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,YAAY,EACV,IAAI,EACJ,WAAW,EACX,cAAc,EACd,eAAe,EACf,IAAI,EACJ,WAAW,EACX,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEpF;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBAEd,IAAI,EAAE,cAAc;CAQjC;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,WAAW,CAEzD"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FreeAppStore } from '@freeappstore/sdk';
|
|
2
2
|
import { Database } from './db.js';
|
|
3
|
+
import { Storage } from './storage.js';
|
|
3
4
|
import { SubscriptionApi } from './subscription.js';
|
|
4
5
|
import { LicenseApi } from './license.js';
|
|
5
6
|
/**
|
|
@@ -12,12 +13,14 @@ export class ProAppStore extends FreeAppStore {
|
|
|
12
13
|
subscription;
|
|
13
14
|
license;
|
|
14
15
|
db;
|
|
16
|
+
storage;
|
|
15
17
|
constructor(opts) {
|
|
16
18
|
super({ appId: opts.appId, ...(opts.fasApiBase && { apiBase: opts.fasApiBase }) });
|
|
17
19
|
const proApiBase = opts.proApiBase ?? 'https://api.proappstore.online';
|
|
18
20
|
this.subscription = new SubscriptionApi(opts.appId, proApiBase, this.auth);
|
|
19
21
|
this.license = new LicenseApi(opts.appId, proApiBase, this.auth);
|
|
20
22
|
this.db = new Database(opts.appId, opts.dataApiBase ?? `https://data-${opts.appId}.proappstore.online`, this.auth);
|
|
23
|
+
this.storage = new Storage(opts.appId, proApiBase, this.auth);
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
/** Create a new ProAppStore SDK instance. Includes all free + pro features. */
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAwB1C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAClC,YAAY,CAAkB;IAC9B,OAAO,CAAa;IACpB,EAAE,CAAW;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAwB1C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAClC,YAAY,CAAkB;IAC9B,OAAO,CAAa;IACpB,EAAE,CAAW;IACb,OAAO,CAAU;IAE1B,YAAY,IAAoB;QAC9B,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;QACnF,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,gCAAgC,CAAC;QACvE,IAAI,CAAC,YAAY,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3E,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,IAAI,CAAC,EAAE,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,IAAI,gBAAgB,IAAI,CAAC,KAAK,qBAAqB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACnH,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAChE,CAAC;CACF;AAED,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,IAAoB;IAC1C,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface AuthLike {
|
|
2
|
+
token: string | null;
|
|
3
|
+
handleUnauthorized(): void;
|
|
4
|
+
}
|
|
5
|
+
interface UploadResult {
|
|
6
|
+
key: string;
|
|
7
|
+
size: number;
|
|
8
|
+
contentType: string;
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
interface FileInfo {
|
|
12
|
+
key: string;
|
|
13
|
+
size: number;
|
|
14
|
+
uploaded: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* File storage — upload, download, list, delete files.
|
|
18
|
+
* Backed by R2 on the PAS API, scoped to (appId, userId).
|
|
19
|
+
*/
|
|
20
|
+
export declare class Storage {
|
|
21
|
+
private readonly appId;
|
|
22
|
+
private readonly apiBase;
|
|
23
|
+
private readonly auth;
|
|
24
|
+
constructor(appId: string, apiBase: string, auth: AuthLike);
|
|
25
|
+
/** Upload a file. Returns the upload result with the file URL. */
|
|
26
|
+
upload(path: string, data: Blob | ArrayBuffer | Uint8Array, contentType?: string): Promise<UploadResult>;
|
|
27
|
+
/** Download a file. Returns the Response (use .blob(), .arrayBuffer(), etc.). */
|
|
28
|
+
download(path: string): Promise<Response>;
|
|
29
|
+
/** Get a URL for a file (for use in <img src> etc). Requires auth header. */
|
|
30
|
+
url(path: string): string;
|
|
31
|
+
/** List all files for the current user in this app. */
|
|
32
|
+
list(): Promise<FileInfo[]>;
|
|
33
|
+
/** Delete a file. */
|
|
34
|
+
delete(path: string): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kBAAkB,IAAI,IAAI,CAAC;CAC5B;AAED,UAAU,YAAY;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,QAAQ;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,OAAO;IAEhB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFJ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,QAAQ;IAGjC,kEAAkE;IAC5D,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,UAAU,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IA0B9G,iFAAiF;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmB/C,6EAA6E;IAC7E,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIzB,uDAAuD;IACjD,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAmBjC,qBAAqB;IACf,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkB1C"}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File storage — upload, download, list, delete files.
|
|
3
|
+
* Backed by R2 on the PAS API, scoped to (appId, userId).
|
|
4
|
+
*/
|
|
5
|
+
export class Storage {
|
|
6
|
+
appId;
|
|
7
|
+
apiBase;
|
|
8
|
+
auth;
|
|
9
|
+
constructor(appId, apiBase, auth) {
|
|
10
|
+
this.appId = appId;
|
|
11
|
+
this.apiBase = apiBase;
|
|
12
|
+
this.auth = auth;
|
|
13
|
+
}
|
|
14
|
+
/** Upload a file. Returns the upload result with the file URL. */
|
|
15
|
+
async upload(path, data, contentType) {
|
|
16
|
+
const token = this.auth.token;
|
|
17
|
+
if (!token)
|
|
18
|
+
throw new Error('Not signed in.');
|
|
19
|
+
const url = `${this.apiBase}/v1/apps/${encodeURIComponent(this.appId)}/storage/${path}`;
|
|
20
|
+
const response = await fetch(url, {
|
|
21
|
+
method: 'PUT',
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: `Bearer ${token}`,
|
|
24
|
+
'Content-Type': contentType || (data instanceof Blob ? data.type : 'application/octet-stream'),
|
|
25
|
+
},
|
|
26
|
+
body: data,
|
|
27
|
+
});
|
|
28
|
+
if (response.status === 401) {
|
|
29
|
+
this.auth.handleUnauthorized();
|
|
30
|
+
throw new Error('Not signed in.');
|
|
31
|
+
}
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
const text = await response.text();
|
|
34
|
+
throw new Error(`storage.upload failed (${response.status}): ${text}`);
|
|
35
|
+
}
|
|
36
|
+
return (await response.json());
|
|
37
|
+
}
|
|
38
|
+
/** Download a file. Returns the Response (use .blob(), .arrayBuffer(), etc.). */
|
|
39
|
+
async download(path) {
|
|
40
|
+
const token = this.auth.token;
|
|
41
|
+
if (!token)
|
|
42
|
+
throw new Error('Not signed in.');
|
|
43
|
+
const url = `${this.apiBase}/v1/apps/${encodeURIComponent(this.appId)}/storage/${path}`;
|
|
44
|
+
const response = await fetch(url, {
|
|
45
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
46
|
+
});
|
|
47
|
+
if (response.status === 401) {
|
|
48
|
+
this.auth.handleUnauthorized();
|
|
49
|
+
throw new Error('Not signed in.');
|
|
50
|
+
}
|
|
51
|
+
if (response.status === 404)
|
|
52
|
+
throw new Error('File not found.');
|
|
53
|
+
if (!response.ok)
|
|
54
|
+
throw new Error(`storage.download failed: ${response.status}`);
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
/** Get a URL for a file (for use in <img src> etc). Requires auth header. */
|
|
58
|
+
url(path) {
|
|
59
|
+
return `${this.apiBase}/v1/apps/${encodeURIComponent(this.appId)}/storage/${path}`;
|
|
60
|
+
}
|
|
61
|
+
/** List all files for the current user in this app. */
|
|
62
|
+
async list() {
|
|
63
|
+
const token = this.auth.token;
|
|
64
|
+
if (!token)
|
|
65
|
+
throw new Error('Not signed in.');
|
|
66
|
+
const url = `${this.apiBase}/v1/apps/${encodeURIComponent(this.appId)}/files`;
|
|
67
|
+
const response = await fetch(url, {
|
|
68
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
69
|
+
});
|
|
70
|
+
if (response.status === 401) {
|
|
71
|
+
this.auth.handleUnauthorized();
|
|
72
|
+
throw new Error('Not signed in.');
|
|
73
|
+
}
|
|
74
|
+
if (!response.ok)
|
|
75
|
+
throw new Error(`storage.list failed: ${response.status}`);
|
|
76
|
+
const data = (await response.json());
|
|
77
|
+
return data.files;
|
|
78
|
+
}
|
|
79
|
+
/** Delete a file. */
|
|
80
|
+
async delete(path) {
|
|
81
|
+
const token = this.auth.token;
|
|
82
|
+
if (!token)
|
|
83
|
+
throw new Error('Not signed in.');
|
|
84
|
+
const url = `${this.apiBase}/v1/apps/${encodeURIComponent(this.appId)}/storage/${path}`;
|
|
85
|
+
const response = await fetch(url, {
|
|
86
|
+
method: 'DELETE',
|
|
87
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
88
|
+
});
|
|
89
|
+
if (response.status === 401) {
|
|
90
|
+
this.auth.handleUnauthorized();
|
|
91
|
+
throw new Error('Not signed in.');
|
|
92
|
+
}
|
|
93
|
+
if (!response.ok && response.status !== 404) {
|
|
94
|
+
throw new Error(`storage.delete failed: ${response.status}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,MAAM,OAAO,OAAO;IAEC;IACA;IACA;IAHnB,YACmB,KAAa,EACb,OAAe,EACf,IAAc;QAFd,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAU;IAC9B,CAAC;IAEJ,kEAAkE;IAClE,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,IAAqC,EAAE,WAAoB;QACpF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9B,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAE9C,MAAM,GAAG,GAAG,GAAG,IAAI,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