@polardbx/pxbaas-client 0.0.0-stage → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -2
- package/dist/drivers/apps.driver.d.ts +121 -0
- package/dist/drivers/apps.driver.d.ts.map +1 -0
- package/dist/drivers/apps.driver.js +90 -0
- package/dist/drivers/apps.driver.js.map +1 -0
- package/dist/drivers/auth-admin.driver.d.ts +78 -0
- package/dist/drivers/auth-admin.driver.d.ts.map +1 -0
- package/dist/drivers/auth-admin.driver.js +145 -0
- package/dist/drivers/auth-admin.driver.js.map +1 -0
- package/dist/drivers/functions.driver.d.ts +75 -0
- package/dist/drivers/functions.driver.d.ts.map +1 -0
- package/dist/drivers/functions.driver.js +173 -0
- package/dist/drivers/functions.driver.js.map +1 -0
- package/dist/drivers/meta.driver.d.ts +77 -0
- package/dist/drivers/meta.driver.d.ts.map +1 -0
- package/dist/drivers/meta.driver.js +191 -0
- package/dist/drivers/meta.driver.js.map +1 -0
- package/dist/drivers/share-links.driver.d.ts +42 -0
- package/dist/drivers/share-links.driver.d.ts.map +1 -0
- package/dist/drivers/share-links.driver.js +53 -0
- package/dist/drivers/share-links.driver.js.map +1 -0
- package/dist/drivers/storage.driver.d.ts +72 -0
- package/dist/drivers/storage.driver.d.ts.map +1 -0
- package/dist/drivers/storage.driver.js +171 -0
- package/dist/drivers/storage.driver.js.map +1 -0
- package/dist/drivers/tenant-ddl.driver.d.ts +106 -0
- package/dist/drivers/tenant-ddl.driver.d.ts.map +1 -0
- package/dist/drivers/tenant-ddl.driver.js +131 -0
- package/dist/drivers/tenant-ddl.driver.js.map +1 -0
- package/dist/drivers/zero.driver.d.ts +78 -0
- package/dist/drivers/zero.driver.d.ts.map +1 -0
- package/dist/drivers/zero.driver.js +117 -0
- package/dist/drivers/zero.driver.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -3
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @polardbx/pxbaas-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared HTTP client SDK for [PolarDB-X BaaS](https://github.com/polardbx/mysql-supabase) (MySQL-Supabase) data plane APIs. This is the transport layer used by the [`@polardbx/pxbaas`](https://www.npmjs.com/package/@polardbx/pxbaas) CLI; you can also depend on it directly to script BaaS operations from Node.js.
|
|
4
|
+
|
|
5
|
+
Covered API surfaces:
|
|
6
|
+
|
|
7
|
+
- Meta API (`/pg/*`) — tables, schema, SQL query
|
|
8
|
+
- Functions Management API (`/v1/projects/*`) — Edge Function deploy/list/delete
|
|
9
|
+
- Apps & share-links drivers — webapp mounts and secure sharing
|
|
10
|
+
- Storage API (`/storage/v1/*`) — objects and buckets
|
|
11
|
+
- Auth Admin API (`/auth/v1/admin/*`) — user administration
|
|
12
|
+
- Tenant self-service DDL / RLS driver (multi-tenant, per-tenant `service_role`)
|
|
13
|
+
- Zero provisioning driver (PolarDB-X Zero PXBaas)
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Node.js >= 20
|
|
18
|
+
- ESM (`"type": "module"`); types ship in `dist/index.d.ts`
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @polardbx/pxbaas-client
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Drivers are constructed per endpoint with your tenant keys; keys are passed by the caller (the CLI sources them from its keyring-backed profile store).
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { MetaDriver } from "@polardbx/pxbaas-client";
|
|
32
|
+
|
|
33
|
+
const meta = new MetaDriver({
|
|
34
|
+
endpoint: "https://your-baas-endpoint",
|
|
35
|
+
anonKey: process.env.BAAS_ANON_KEY!,
|
|
36
|
+
serviceRoleKey: process.env.BAAS_SERVICE_ROLE_KEY, // admin operations
|
|
37
|
+
tenantId: process.env.BAAS_TENANT_ID, // multi-tenant deployments
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const tables = await meta.listTables();
|
|
41
|
+
const rows = await meta.query("select 1");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Other drivers (`FunctionsDriver`, `AppsDriver`, `ShareLinksDriver`, `StorageDriver`, `AuthAdminDriver`, `TenantDdlDriver`, `ZeroDriver`) follow the same options-object pattern; see `dist/index.d.ts` for the full typed surface.
|
|
45
|
+
|
|
46
|
+
## Versioning
|
|
47
|
+
|
|
48
|
+
Versioned in lockstep with `@polardbx/pxbaas` (the CLI depends on this package via `workspace:*` in the monorepo, rewritten to the real version at publish time). Always upgrade both together.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export type AppOriginMode = "shared" | "isolated";
|
|
2
|
+
export type AppMountStatus = "ACTIVE" | "DISABLED";
|
|
3
|
+
export interface AppCapabilities {
|
|
4
|
+
schemaVersions: number[];
|
|
5
|
+
appEndpoint: string | null;
|
|
6
|
+
originMode?: AppOriginMode;
|
|
7
|
+
hostEnforced?: boolean;
|
|
8
|
+
publicExposureAllowed?: boolean;
|
|
9
|
+
publicStatic: boolean;
|
|
10
|
+
nativeDeno: boolean;
|
|
11
|
+
honoVersion: string | null;
|
|
12
|
+
honoOfflineReady?: boolean;
|
|
13
|
+
/** Curated SSR runtime allow-list (name@version) reported by the instance (W9). */
|
|
14
|
+
ssrLibs?: string[];
|
|
15
|
+
binaryAssets: boolean;
|
|
16
|
+
spaFallback: boolean;
|
|
17
|
+
functionSecrets: boolean;
|
|
18
|
+
egressPolicies: string[];
|
|
19
|
+
privateShare: boolean;
|
|
20
|
+
persistentSession: boolean;
|
|
21
|
+
sessionMode?: "none" | "proxy-injected-header";
|
|
22
|
+
sessionHeaders?: string[];
|
|
23
|
+
sessionCookie?: {
|
|
24
|
+
name: string;
|
|
25
|
+
scope: "per-mount";
|
|
26
|
+
httponly: boolean;
|
|
27
|
+
sameSite: string;
|
|
28
|
+
} | null;
|
|
29
|
+
sessionTenantBound?: boolean;
|
|
30
|
+
sessionStateful?: boolean;
|
|
31
|
+
limits: {
|
|
32
|
+
maxFiles: number;
|
|
33
|
+
maxFileBytes: number;
|
|
34
|
+
maxBundleBytes: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface AppMount {
|
|
38
|
+
id: string;
|
|
39
|
+
mountId: string;
|
|
40
|
+
tenantId: string;
|
|
41
|
+
appName: string;
|
|
42
|
+
activeFunctionSlug: string | null;
|
|
43
|
+
previousFunctionSlug: string | null;
|
|
44
|
+
generation: number;
|
|
45
|
+
status: AppMountStatus;
|
|
46
|
+
frontendRouting: "FILES";
|
|
47
|
+
backendEnabled: boolean;
|
|
48
|
+
expiresAt: string | null;
|
|
49
|
+
createdBy: string | null;
|
|
50
|
+
createdAt: string;
|
|
51
|
+
updatedAt: string;
|
|
52
|
+
url: string;
|
|
53
|
+
}
|
|
54
|
+
export interface CreateAppOptions {
|
|
55
|
+
appName: string;
|
|
56
|
+
tenantId?: string;
|
|
57
|
+
expiresAt?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface PublishAppOptions {
|
|
60
|
+
candidateFunctionSlug: string;
|
|
61
|
+
expectedGeneration: number;
|
|
62
|
+
tenantId?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ChangeAppGenerationOptions {
|
|
65
|
+
expectedGeneration: number;
|
|
66
|
+
tenantId?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface DestroyAppOptions {
|
|
69
|
+
/** Reclaim an orphan candidate the caller uploaded but never published. */
|
|
70
|
+
candidateFunctionSlug?: string;
|
|
71
|
+
/** Opt-in CAS guard; omit to destroy unconditionally. */
|
|
72
|
+
expectedGeneration?: number;
|
|
73
|
+
tenantId?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface AppDestroyFunctionResult {
|
|
76
|
+
slug: string;
|
|
77
|
+
deleted: boolean;
|
|
78
|
+
error?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface AppDestroyResult {
|
|
81
|
+
destroyed: boolean;
|
|
82
|
+
mountId: string;
|
|
83
|
+
appName: string;
|
|
84
|
+
tenantId: string;
|
|
85
|
+
alreadyGone?: boolean;
|
|
86
|
+
deletedFunctions: AppDestroyFunctionResult[];
|
|
87
|
+
}
|
|
88
|
+
export interface AppsDriverOptions {
|
|
89
|
+
endpoint: string;
|
|
90
|
+
serviceRoleKey: string;
|
|
91
|
+
projectRef?: string;
|
|
92
|
+
timeout?: number;
|
|
93
|
+
}
|
|
94
|
+
export interface AppApiFailure {
|
|
95
|
+
code: string;
|
|
96
|
+
message: string;
|
|
97
|
+
}
|
|
98
|
+
export declare class AppsApiError extends Error {
|
|
99
|
+
readonly code: string;
|
|
100
|
+
readonly status?: number;
|
|
101
|
+
constructor(code: string, message: string, status?: number);
|
|
102
|
+
}
|
|
103
|
+
export declare class AppsDriver {
|
|
104
|
+
private readonly client;
|
|
105
|
+
constructor(options: AppsDriverOptions);
|
|
106
|
+
capabilities(): Promise<AppCapabilities>;
|
|
107
|
+
create(options: CreateAppOptions): Promise<AppMount>;
|
|
108
|
+
get(mountId: string, tenantId?: string): Promise<AppMount>;
|
|
109
|
+
publish(mountId: string, options: PublishAppOptions): Promise<AppMount>;
|
|
110
|
+
rollback(mountId: string, options: ChangeAppGenerationOptions): Promise<AppMount>;
|
|
111
|
+
unpublish(mountId: string, options: ChangeAppGenerationOptions): Promise<AppMount>;
|
|
112
|
+
/**
|
|
113
|
+
* Permanently tear down a Webapp: reclaim its edge-func candidates and delete
|
|
114
|
+
* the mount-id record. Idempotent (an already-gone mount returns destroyed).
|
|
115
|
+
* DB business tables are NOT touched.
|
|
116
|
+
*/
|
|
117
|
+
destroy(mountId: string, options?: DestroyAppOptions): Promise<AppDestroyResult>;
|
|
118
|
+
private request;
|
|
119
|
+
}
|
|
120
|
+
export declare function normalizeAppsError(error: unknown): AppsApiError;
|
|
121
|
+
//# sourceMappingURL=apps.driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps.driver.d.ts","sourceRoot":"","sources":["../../src/drivers/apps.driver.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,UAAU,CAAC;AAClD,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEnD,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,EAAE,OAAO,CAAC;IAE3B,WAAW,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAAC;IAC/C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,OAAO,CAAC;QAClB,QA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Q1D,OAAO,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,QAAQ,CAAC;IASd,QAAQ,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,QAAQ,CAAC;IASd,SAAS,CACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,QAAQ,CAAC;IASpB;;;;OAIG;IACG,OAAO,CACX,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,CAAC;YASd,OAAO;CAiBtB;AAQD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CA8B/D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
export class AppsApiError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
constructor(code, message, status) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "AppsApiError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.status = status;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class AppsDriver {
|
|
13
|
+
client;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
const endpoint = options.endpoint.replace(/\/$/, "");
|
|
16
|
+
this.client = axios.create({
|
|
17
|
+
baseURL: `${endpoint}/v1/projects/${encodeURIComponent(options.projectRef ?? "default")}/apps`,
|
|
18
|
+
timeout: options.timeout ?? 60_000,
|
|
19
|
+
headers: { Authorization: `Bearer ${options.serviceRoleKey}` },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async capabilities() {
|
|
23
|
+
return this.request(() => this.client.get("/capabilities"));
|
|
24
|
+
}
|
|
25
|
+
async create(options) {
|
|
26
|
+
return this.request(() => this.client.post("", compact(options)));
|
|
27
|
+
}
|
|
28
|
+
async get(mountId, tenantId) {
|
|
29
|
+
return this.request(() => this.client.get(`/${encodeURIComponent(mountId)}`, {
|
|
30
|
+
params: tenantId ? { tenantId } : undefined,
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
async publish(mountId, options) {
|
|
34
|
+
return this.request(() => this.client.post(`/${encodeURIComponent(mountId)}/publish`, compact(options)));
|
|
35
|
+
}
|
|
36
|
+
async rollback(mountId, options) {
|
|
37
|
+
return this.request(() => this.client.post(`/${encodeURIComponent(mountId)}/rollback`, compact(options)));
|
|
38
|
+
}
|
|
39
|
+
async unpublish(mountId, options) {
|
|
40
|
+
return this.request(() => this.client.post(`/${encodeURIComponent(mountId)}/unpublish`, compact(options)));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Permanently tear down a Webapp: reclaim its edge-func candidates and delete
|
|
44
|
+
* the mount-id record. Idempotent (an already-gone mount returns destroyed).
|
|
45
|
+
* DB business tables are NOT touched.
|
|
46
|
+
*/
|
|
47
|
+
async destroy(mountId, options = {}) {
|
|
48
|
+
return this.request(() => this.client.post(`/${encodeURIComponent(mountId)}/destroy`, compact(options)));
|
|
49
|
+
}
|
|
50
|
+
async request(operation) {
|
|
51
|
+
try {
|
|
52
|
+
const response = await operation();
|
|
53
|
+
if (response.data?.status !== "ok" || response.data.data === undefined) {
|
|
54
|
+
throw new AppsApiError("APP_RESPONSE_INVALID", "Apps API returned an invalid response");
|
|
55
|
+
}
|
|
56
|
+
return response.data.data;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof AppsApiError)
|
|
60
|
+
throw error;
|
|
61
|
+
throw normalizeAppsError(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function compact(value) {
|
|
66
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
|
|
67
|
+
}
|
|
68
|
+
export function normalizeAppsError(error) {
|
|
69
|
+
if (!axios.isAxiosError(error)) {
|
|
70
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
71
|
+
return new AppsApiError("APP_UNKNOWN_ERROR", message);
|
|
72
|
+
}
|
|
73
|
+
const axiosError = error;
|
|
74
|
+
const status = axiosError.response?.status;
|
|
75
|
+
const body = axiosError.response?.data;
|
|
76
|
+
const rawCode = body?.code ?? body?.error?.code;
|
|
77
|
+
const rawMessage = body?.message ?? body?.error?.message;
|
|
78
|
+
const code = typeof rawCode === "string"
|
|
79
|
+
? rawCode
|
|
80
|
+
: status
|
|
81
|
+
? `APP_HTTP_${status}`
|
|
82
|
+
: "APP_NETWORK_ERROR";
|
|
83
|
+
const message = typeof rawMessage === "string"
|
|
84
|
+
? rawMessage
|
|
85
|
+
: status
|
|
86
|
+
? `Apps API request failed (HTTP ${status})`
|
|
87
|
+
: axiosError.message || "Apps API network request failed";
|
|
88
|
+
return new AppsApiError(code, message, status);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=apps.driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps.driver.js","sourceRoot":"","sources":["../../src/drivers/apps.driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8C,MAAM,OAAO,CAAC;AAoHnE,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAS;IACb,MAAM,CAAU;IAEzB,YAAY,IAAY,EAAE,OAAe,EAAE,MAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,UAAU;IACJ,MAAM,CAAgB;IAEvC,YAAY,OAA0B;QACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,GA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
|
2
|
+
* Auth Admin Driver - GoTrue Admin API client
|
|
3
|
+
*
|
|
4
|
+
* Endpoints:
|
|
5
|
+
* - GET /auth/v1/admin/users - List users
|
|
6
|
+
* - GET /auth/v1/admin/users/{id} - Get user
|
|
7
|
+
* - POST /auth/v1/admin/users - Create user
|
|
8
|
+
* - DELETE /auth/v1/admin/users/{id} - Delete user
|
|
9
|
+
* - POST /auth/v1/invite - Invite user
|
|
10
|
+
*/
|
|
11
|
+
export interface User {
|
|
12
|
+
id: string;
|
|
13
|
+
aud: string;
|
|
14
|
+
role: string;
|
|
15
|
+
email: string;
|
|
16
|
+
email_confirmed_at?: string;
|
|
17
|
+
phone?: string;
|
|
18
|
+
phone_confirmed_at?: string;
|
|
19
|
+
created_at: string;
|
|
20
|
+
updated_at: string;
|
|
21
|
+
last_sign_in_at?: string;
|
|
22
|
+
app_metadata: Record<string, unknown>;
|
|
23
|
+
user_metadata: Record<string, unknown>;
|
|
24
|
+
identities?: Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
user_id: string;
|
|
27
|
+
identity_data: Record<string, unknown>;
|
|
28
|
+
provider: string;
|
|
29
|
+
last_sign_in_at: string;
|
|
30
|
+
created_at: string;
|
|
31
|
+
updated_at: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export interface CreateUserOptions {
|
|
35
|
+
email: string;
|
|
36
|
+
password: string;
|
|
37
|
+
email_confirm?: boolean;
|
|
38
|
+
user_metadata?: Record<string, unknown>;
|
|
39
|
+
app_metadata?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
export interface AuthAdminDriverOptions {
|
|
42
|
+
endpoint: string;
|
|
43
|
+
serviceRoleKey: string;
|
|
44
|
+
tenantId?: string;
|
|
45
|
+
timeout?: number;
|
|
46
|
+
}
|
|
47
|
+
export declare class AuthAdminDriver {
|
|
48
|
+
private client;
|
|
49
|
+
private serviceRoleKey;
|
|
50
|
+
private tenantId?;
|
|
51
|
+
constructor(options: AuthAdminDriverOptions);
|
|
52
|
+
private getHeaders;
|
|
53
|
+
private handleError;
|
|
54
|
+
/**
|
|
55
|
+
* List all users
|
|
56
|
+
*/
|
|
57
|
+
listUsers(page?: number, perPage?: number): Promise<{
|
|
58
|
+
users: User[];
|
|
59
|
+
total: number;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Get user by ID
|
|
63
|
+
*/
|
|
64
|
+
getUser(userId: string): Promise<User>;
|
|
65
|
+
/**
|
|
66
|
+
* Create a new user
|
|
67
|
+
*/
|
|
68
|
+
createUser(options: CreateUserOptions): Promise<User>;
|
|
69
|
+
/**
|
|
70
|
+
* Delete a user
|
|
71
|
+
*/
|
|
72
|
+
deleteUser(userId: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Invite a user by email
|
|
75
|
+
*/
|
|
76
|
+
inviteUser(email: string): Promise<User>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=auth-admin.driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-admin.driver.d.ts","sourceRoot":"","sources":["../../src/drivers/auth-admin.driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EA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AAC,IAAI,CAAC;IAoB3D;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW/C;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAa/C"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth Admin Driver - GoTrue Admin API client
|
|
3
|
+
*
|
|
4
|
+
* Endpoints:
|
|
5
|
+
* - GET /auth/v1/admin/users - List users
|
|
6
|
+
* - GET /auth/v1/admin/users/{id} - Get user
|
|
7
|
+
* - POST /auth/v1/admin/users - Create user
|
|
8
|
+
* - DELETE /auth/v1/admin/users/{id} - Delete user
|
|
9
|
+
* - POST /auth/v1/invite - Invite user
|
|
10
|
+
*/
|
|
11
|
+
import axios from 'axios';
|
|
12
|
+
export class AuthAdminDriver {
|
|
13
|
+
client;
|
|
14
|
+
serviceRoleKey;
|
|
15
|
+
tenantId;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.serviceRoleKey = options.serviceRoleKey;
|
|
18
|
+
this.tenantId = options.tenantId;
|
|
19
|
+
this.client = axios.create({
|
|
20
|
+
baseURL: `${options.endpoint}/auth/v1`,
|
|
21
|
+
timeout: options.timeout ?? 30000,
|
|
22
|
+
headers: {
|
|
23
|
+
'Authorization': `Bearer ${this.serviceRoleKey}`,
|
|
24
|
+
'apikey': this.serviceRoleKey,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getHeaders() {
|
|
29
|
+
const headers = {
|
|
30
|
+
'Authorization': `Bearer ${this.serviceRoleKey}`,
|
|
31
|
+
'apikey': this.serviceRoleKey,
|
|
32
|
+
};
|
|
33
|
+
if (this.tenantId) {
|
|
34
|
+
headers['X-Tenant-Id'] = this.tenantId;
|
|
35
|
+
}
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
handleError(error) {
|
|
39
|
+
if (axios.isAxiosError(error)) {
|
|
40
|
+
const axiosError = error;
|
|
41
|
+
const status = axiosError.response?.status;
|
|
42
|
+
const data = axiosError.response?.data;
|
|
43
|
+
let message = axiosError.message;
|
|
44
|
+
if (status === 401) {
|
|
45
|
+
message = 'Authentication failed. Please check your service_role key and run "pxbaas login" again.';
|
|
46
|
+
}
|
|
47
|
+
else if (status === 403) {
|
|
48
|
+
message = 'Permission denied. Admin operations require service_role key.';
|
|
49
|
+
}
|
|
50
|
+
else if (status === 404) {
|
|
51
|
+
message = 'User not found. Please check the user ID and try again.';
|
|
52
|
+
}
|
|
53
|
+
else if (status === 422) {
|
|
54
|
+
message = data?.msg ? String(data.msg) : 'Validation failed';
|
|
55
|
+
}
|
|
56
|
+
else if (data?.error_description) {
|
|
57
|
+
message = String(data.error_description);
|
|
58
|
+
}
|
|
59
|
+
else if (data?.msg) {
|
|
60
|
+
message = String(data.msg);
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`Auth Admin API error (${status ?? 'unknown'}): ${message}`);
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* List all users
|
|
68
|
+
*/
|
|
69
|
+
async listUsers(page, perPage) {
|
|
70
|
+
try {
|
|
71
|
+
const params = {};
|
|
72
|
+
if (page !== undefined)
|
|
73
|
+
params.page = page;
|
|
74
|
+
if (perPage !== undefined)
|
|
75
|
+
params.per_page = perPage;
|
|
76
|
+
const response = await this.client.get('/admin/users', {
|
|
77
|
+
headers: this.getHeaders(),
|
|
78
|
+
params,
|
|
79
|
+
});
|
|
80
|
+
const total = parseInt(response.headers['x-total-count'] ?? '0', 10);
|
|
81
|
+
const users = response.data?.users ?? [];
|
|
82
|
+
return {
|
|
83
|
+
users,
|
|
84
|
+
total,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
this.handleError(error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get user by ID
|
|
93
|
+
*/
|
|
94
|
+
async getUser(userId) {
|
|
95
|
+
try {
|
|
96
|
+
const response = await this.client.get(`/admin/users/${userId}`, { headers: this.getHeaders() });
|
|
97
|
+
return response.data;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.handleError(error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a new user
|
|
105
|
+
*/
|
|
106
|
+
async createUser(options) {
|
|
107
|
+
try {
|
|
108
|
+
const response = await this.client.post('/admin/users', {
|
|
109
|
+
email: options.email,
|
|
110
|
+
password: options.password,
|
|
111
|
+
email_confirm: options.email_confirm ?? true,
|
|
112
|
+
user_metadata: options.user_metadata ?? {},
|
|
113
|
+
app_metadata: options.app_metadata ?? {},
|
|
114
|
+
}, { headers: this.getHeaders() });
|
|
115
|
+
return response.data;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
this.handleError(error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Delete a user
|
|
123
|
+
*/
|
|
124
|
+
async deleteUser(userId) {
|
|
125
|
+
try {
|
|
126
|
+
await this.client.delete(`/admin/users/${userId}`, { headers: this.getHeaders() });
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
this.handleError(error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Invite a user by email
|
|
134
|
+
*/
|
|
135
|
+
async inviteUser(email) {
|
|
136
|
+
try {
|
|
137
|
+
const response = await this.client.post('/invite', { email }, { headers: this.getHeaders() });
|
|
138
|
+
return response.data;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
this.handleError(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=auth-admin.driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-admin.driver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I,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,MAAc;QAC7B,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CACtB,gBAAgB,MAAM,EAAE,EACxB,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,CAC/B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,KAAa;QAC5B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACrC,SAAS,EACT,EAAE,KAAK,EAAE,EACT,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,CAC/B,CAAC;YAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functions Driver - Edge Functions Management API client
|
|
3
|
+
*
|
|
4
|
+
* Endpoints:
|
|
5
|
+
* - POST /v1/projects/{ref}/functions/deploy?slug={slug} - Deploy function
|
|
6
|
+
* - GET /v1/projects/{ref}/functions - List functions
|
|
7
|
+
* - GET /v1/projects/{ref}/functions/{slug} - Get function details
|
|
8
|
+
* - DELETE /v1/projects/{ref}/functions/{slug} - Delete function
|
|
9
|
+
*/
|
|
10
|
+
export interface FunctionInfo {
|
|
11
|
+
slug: string;
|
|
12
|
+
name: string;
|
|
13
|
+
status: 'ACTIVE' | 'INACTIVE' | 'DEPLOYING' | 'ERROR';
|
|
14
|
+
version: number;
|
|
15
|
+
entrypoint_path: string;
|
|
16
|
+
verify_jwt: boolean;
|
|
17
|
+
created_at: string;
|
|
18
|
+
updated_at: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DeployOptions {
|
|
21
|
+
slug: string;
|
|
22
|
+
entrypointPath?: string;
|
|
23
|
+
verifyJwt?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Files to upload. `relativePath` (path within the function dir, e.g.
|
|
26
|
+
* `assets/style.css`) is preserved as the multipart filename so nested
|
|
27
|
+
* directory structure survives into `edge_function_files.file_path`;
|
|
28
|
+
* falls back to `basename(path)` when absent (flat single-file deploys).
|
|
29
|
+
*/
|
|
30
|
+
files: Array<{
|
|
31
|
+
path: string;
|
|
32
|
+
relativePath?: string;
|
|
33
|
+
content?: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
export interface FunctionsDriverOptions {
|
|
37
|
+
endpoint: string;
|
|
38
|
+
serviceRoleKey: string;
|
|
39
|
+
tenantId?: string;
|
|
40
|
+
projectRef?: string;
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}
|
|
43
|
+
export declare class FunctionsDriver {
|
|
44
|
+
private client;
|
|
45
|
+
private serviceRoleKey;
|
|
46
|
+
private tenantId?;
|
|
47
|
+
private projectRef;
|
|
48
|
+
constructor(options: FunctionsDriverOptions);
|
|
49
|
+
private getHeaders;
|
|
50
|
+
private handleError;
|
|
51
|
+
/**
|
|
52
|
+
* Deploy a function
|
|
53
|
+
*
|
|
54
|
+
* IMPORTANT: metadata must be passed as a form field WITHOUT filename,
|
|
55
|
+
* not as a file upload. This is a common source of 400 errors.
|
|
56
|
+
*/
|
|
57
|
+
deploy(options: DeployOptions): Promise<FunctionInfo>;
|
|
58
|
+
/**
|
|
59
|
+
* List all deployed functions
|
|
60
|
+
*/
|
|
61
|
+
list(): Promise<FunctionInfo[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Get function details
|
|
64
|
+
*/
|
|
65
|
+
get(slug: string): Promise<FunctionInfo>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete a function
|
|
68
|
+
*/
|
|
69
|
+
delete(slug: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Get content type based on file extension
|
|
72
|
+
*/
|
|
73
|
+
private getContentType;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=functions.driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.driver.d.ts","sourceRoot":"","sources":["../../src/drivers/functions.driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;OAKG;IACH,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzE;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,cAAc,C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