@ragable/sdk 0.8.1 → 0.8.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/dist/index.d.mts +112 -1
- package/dist/index.d.ts +112 -1
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4556,6 +4556,91 @@ function createBrowserClient(options) {
|
|
|
4556
4556
|
}
|
|
4557
4557
|
var createRagableBrowserClient = createBrowserClient;
|
|
4558
4558
|
|
|
4559
|
+
// src/server.ts
|
|
4560
|
+
function optionsForPrivilege(config, privilege) {
|
|
4561
|
+
const base = {
|
|
4562
|
+
organizationId: config.organizationId,
|
|
4563
|
+
...config.websiteId !== void 0 ? { websiteId: config.websiteId } : {},
|
|
4564
|
+
...config.authGroupId !== void 0 ? { authGroupId: config.authGroupId } : {},
|
|
4565
|
+
...config.databaseInstanceId !== void 0 ? { databaseInstanceId: config.databaseInstanceId } : {},
|
|
4566
|
+
...config.fetch !== void 0 ? { fetch: config.fetch } : {},
|
|
4567
|
+
...config.headers !== void 0 ? { headers: config.headers } : {}
|
|
4568
|
+
};
|
|
4569
|
+
if (privilege === "admin") {
|
|
4570
|
+
const key = config.adminKey?.trim();
|
|
4571
|
+
if (!key) {
|
|
4572
|
+
throw new RagableError(
|
|
4573
|
+
"Admin privilege requires `adminKey` (the auth group's data-admin key). It is not available \u2014 admin functions may be disabled for this project.",
|
|
4574
|
+
403,
|
|
4575
|
+
{ code: "SDK_ADMIN_KEY_REQUIRED" }
|
|
4576
|
+
);
|
|
4577
|
+
}
|
|
4578
|
+
return { ...base, dataAuth: "admin", dataStaticKey: key };
|
|
4579
|
+
}
|
|
4580
|
+
return {
|
|
4581
|
+
...base,
|
|
4582
|
+
dataAuth: "auto",
|
|
4583
|
+
getAccessToken: () => config.callerToken ?? null,
|
|
4584
|
+
...config.publicAnonKey !== void 0 ? { dataStaticKey: config.publicAnonKey } : {}
|
|
4585
|
+
};
|
|
4586
|
+
}
|
|
4587
|
+
var RagableServerClient = class _RagableServerClient {
|
|
4588
|
+
constructor(config, privilege) {
|
|
4589
|
+
this.config = config;
|
|
4590
|
+
__publicField(this, "database");
|
|
4591
|
+
__publicField(this, "db");
|
|
4592
|
+
__publicField(this, "storage");
|
|
4593
|
+
__publicField(this, "mail");
|
|
4594
|
+
__publicField(this, "functions");
|
|
4595
|
+
__publicField(this, "ai");
|
|
4596
|
+
__publicField(this, "agents");
|
|
4597
|
+
/** Which credential this client is using. */
|
|
4598
|
+
__publicField(this, "privilege");
|
|
4599
|
+
this.privilege = privilege;
|
|
4600
|
+
const options = optionsForPrivilege(config, privilege);
|
|
4601
|
+
const transport = new Transport({
|
|
4602
|
+
...options.fetch !== void 0 ? { fetch: options.fetch } : {},
|
|
4603
|
+
...options.headers !== void 0 ? { headers: options.headers } : {},
|
|
4604
|
+
...options.transport
|
|
4605
|
+
});
|
|
4606
|
+
this.database = new RagableBrowserDatabaseClient(options, null);
|
|
4607
|
+
this.database._setTransport(transport);
|
|
4608
|
+
this.db = this.database;
|
|
4609
|
+
this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch), null);
|
|
4610
|
+
this.mail = new RagableBrowserMailClient(options, null);
|
|
4611
|
+
this.functions = new RagableBrowserFunctionsClient(options, null).asInvoker();
|
|
4612
|
+
this.ai = new RagableBrowserAiClient({
|
|
4613
|
+
organizationId: options.organizationId,
|
|
4614
|
+
...options.websiteId !== void 0 ? { websiteId: options.websiteId } : {},
|
|
4615
|
+
...options.fetch !== void 0 ? { fetch: options.fetch } : {},
|
|
4616
|
+
...options.headers !== void 0 ? { headers: options.headers } : {},
|
|
4617
|
+
apiBase: normalizeBrowserApiBase()
|
|
4618
|
+
});
|
|
4619
|
+
this.agents = new RagableBrowserAgentsClient(options);
|
|
4620
|
+
}
|
|
4621
|
+
/**
|
|
4622
|
+
* A client authenticated with the **data-admin key** — bypasses collection
|
|
4623
|
+
* security (owner/group/claim grants do not apply) and can write protected
|
|
4624
|
+
* collections. Throws `SDK_ADMIN_KEY_REQUIRED` when no admin key is configured.
|
|
4625
|
+
*/
|
|
4626
|
+
asAdmin() {
|
|
4627
|
+
return new _RagableServerClient(this.config, "admin");
|
|
4628
|
+
}
|
|
4629
|
+
/**
|
|
4630
|
+
* A client scoped to the invoking end user's identity (respects collection
|
|
4631
|
+
* security). This is already the default; use it to drop back from `asAdmin()`.
|
|
4632
|
+
*/
|
|
4633
|
+
asCaller() {
|
|
4634
|
+
return new _RagableServerClient(this.config, "caller");
|
|
4635
|
+
}
|
|
4636
|
+
};
|
|
4637
|
+
function createServerClient(config) {
|
|
4638
|
+
return new RagableServerClient(
|
|
4639
|
+
config,
|
|
4640
|
+
config.defaultPrivilege ?? "caller"
|
|
4641
|
+
);
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4559
4644
|
// src/index.ts
|
|
4560
4645
|
function createClient(options) {
|
|
4561
4646
|
return createBrowserClient(options);
|
|
@@ -4592,6 +4677,7 @@ export {
|
|
|
4592
4677
|
RagableError,
|
|
4593
4678
|
RagableNetworkError,
|
|
4594
4679
|
RagableSdkError,
|
|
4680
|
+
RagableServerClient,
|
|
4595
4681
|
RagableTimeoutError,
|
|
4596
4682
|
SessionStorageAdapter,
|
|
4597
4683
|
Transport,
|
|
@@ -4606,6 +4692,7 @@ export {
|
|
|
4606
4692
|
createBrowserClient,
|
|
4607
4693
|
createClient,
|
|
4608
4694
|
createRagableBrowserClient,
|
|
4695
|
+
createServerClient,
|
|
4609
4696
|
createStreamResultFromParts,
|
|
4610
4697
|
detectStorage,
|
|
4611
4698
|
effectiveDataAuth,
|