@dataql/node
Version:
DataQL core SDK for unified data management with MongoDB and GraphQL - Production Multi-Cloud Ready
119 lines (118 loc) • 5.25 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Auth = exports.BaseDataQLClient = exports.SubdocumentCollection = exports.DocumentScope = exports.createDocumentScope = exports.Data = void 0;
var Data_js_1 = require("./Data.js");
Object.defineProperty(exports, "Data", { enumerable: true, get: function () { return Data_js_1.Data; } });
var DocumentScope_js_1 = require("./DocumentScope.js");
Object.defineProperty(exports, "createDocumentScope", { enumerable: true, get: function () { return DocumentScope_js_1.createDocumentScope; } });
Object.defineProperty(exports, "DocumentScope", { enumerable: true, get: function () { return DocumentScope_js_1.DocumentScope; } });
Object.defineProperty(exports, "SubdocumentCollection", { enumerable: true, get: function () { return DocumentScope_js_1.SubdocumentCollection; } });
var BaseDataQLClient_js_1 = require("./BaseDataQLClient.js");
Object.defineProperty(exports, "BaseDataQLClient", { enumerable: true, get: function () { return BaseDataQLClient_js_1.BaseDataQLClient; } });
__exportStar(require("./types.js"), exports);
class Auth {
constructor(binding) {
this.binding = binding;
}
async signInAnonymous(deviceId) {
const response = await this.binding.signInAnonymous(new Request("https://dummy", {
method: "POST",
headers: { "x-device-id": deviceId },
}));
const data = typeof response.json === "function" ? await response.json() : response;
return {
sessionId: data.sessionId || data.session_id || data.session?.id || data.id,
userId: data.user?.id || data.userId || data.user_id,
token: data.token || data.sessionToken || data.session_token,
};
}
async createUser(deviceId) {
return this.signInAnonymous(deviceId);
}
async decryptApiKey(userId) {
return await this.binding.decryptApiKey(new Request("https://dummy", {
method: "POST",
body: JSON.stringify({ userId }),
headers: { "Content-Type": "application/json" },
}));
}
async validateApiKey(apiKey) {
return await this.binding.validateApiKey(new Request("https://dummy", {
method: "POST",
body: JSON.stringify({ apiKey }),
headers: { "Content-Type": "application/json" },
}));
}
// --- Organization Management ---
async createOrganization(data) {
return await this.binding.createOrganization(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
async updateOrganization(data) {
return await this.binding.updateOrganization(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
async deleteOrganization(data) {
return await this.binding.deleteOrganization(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
async getFullOrganization(data) {
return await this.binding.getFullOrganization(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
async listOrganizations(data) {
return await this.binding.listOrganizations(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
async addMember(data) {
return await this.binding.addMember(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
async updateMemberRole(data) {
return await this.binding.updateMemberRole(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
async removeMember(data) {
return await this.binding.removeMember(new Request("https://dummy", {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
}));
}
}
exports.Auth = Auth;