@baqhub/sdk-react
Version:
The official React SDK for the BAQ federated app platform.
89 lines (88 loc) • 3.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StoreIdentity = void 0;
const sdk_1 = require("@baqhub/sdk");
//
// API.
//
function buildAuthenticatedIdentity(authState) {
const client = sdk_1.Client.authenticated(authState);
const findClient = () => client;
const blobUrlBuilder = client.blobUrlBuilderFor(authState.entityRecord);
return {
isAuthenticated: true,
entityRecord: sdk_1.Record.toSelf(authState.entityRecord),
findClient,
blobUrlBuilder,
discover: client.discover,
downloadBlob: client.downloadBlob,
};
}
function buildUnauthenticatedIdentity() {
const entity = "never.baq.dev";
const date = new Date("2024-01-01T01:01:00.000Z");
const clients = new Map();
const findClient = e => {
if (e === entity) {
throw new Error("Authenticated Store required.");
}
const existingClient = clients.get(e);
if (existingClient) {
return existingClient;
}
const newClient = sdk_1.Client.ofEntity(e);
clients.set(e, newClient);
return newClient;
};
const blobUrlBuilder = (record, blob, expiresInSeconds) => {
const client = findClient(record.author.entity);
const entityRecord = client.getEntityRecordSync();
const builder = client.blobUrlBuilderFor(entityRecord);
return builder(record, blob, expiresInSeconds);
};
const discover = (entity, signal) => {
const client = findClient(entity);
return client.getEntityRecord(signal);
};
const downloadBlob = (record, blob, signal) => {
const client = findClient(record.author.entity);
return client.downloadBlob(record, blob, signal);
};
return {
isAuthenticated: false,
entityRecord: {
author: { entity },
id: "00000000000000000000000000000000",
source: sdk_1.RecordSource.SELF,
createdAt: date,
receivedAt: date,
version: {
author: { entity },
createdAt: date,
receivedAt: date,
hash: "0000000000000000000000000000000000000000000000000000000000000000",
},
type: {
entity: sdk_1.Constants.systemEntity,
recordId: "80be958368dd414fabb9420647daa1ec",
versionHash: "5869ed5eb6b565b92990ecfda31b4eb7e837489cb4799a534c00e3fd6ca756e9",
},
content: {
previousEntities: [],
signingKeys: [],
profile: {},
servers: [],
},
mode: sdk_1.RecordMode.SYNCED,
permissions: sdk_1.RecordPermissions.public,
},
findClient,
blobUrlBuilder,
discover,
downloadBlob,
};
}
exports.StoreIdentity = {
new: buildAuthenticatedIdentity,
newUnauthenticated: buildUnauthenticatedIdentity,
};