New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fluido/dreno-core

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluido/dreno-core - npm Package Compare versions

Comparing version

to
0.0.1-alpha-4

339

dist/cjs/index.js

@@ -29,24 +29,2 @@ "use strict";

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var __privateMethod = (obj, member, method) => {
__accessCheck(obj, member, "access private method");
return method;
};

@@ -58,3 +36,2 @@ // src/index.ts

DeviceCredentialSchema: () => DeviceCredentialSchema,
DrenoClient: () => DrenoClient,
ENV_KEYS: () => ENV_KEYS,

@@ -76,3 +53,4 @@ ExternalAccountSchema: () => ExternalAccountSchema,

UserSchema: () => UserSchema,
VolatileHashSchema: () => VolatileHashSchema
VolatileHashSchema: () => VolatileHashSchema,
createDrenoClient: () => createDrenoClient
});

@@ -268,197 +246,150 @@ module.exports = __toCommonJS(src_exports);

var import_js_cookie = __toESM(require("js-cookie"));
// src/assertions.ts
function assertAuthorizationsKeys(keys) {
if (!keys) {
throw new Error("Authorization keys are not defined");
async function createDrenoClient(authKey) {
if (!/^[a-zA-Z0-9\-_]+:[a-zA-Z0-9.]+/.test(authKey)) {
throw new Error("Invalid auth key");
}
return true;
}
// src/client.ts
var _projectId, _projectKey, _keys, _authorized, _user, _lock, _checkProjectAuthorization, checkProjectAuthorization_fn;
var DrenoClient = class {
constructor(authKey) {
__privateAdd(this, _checkProjectAuthorization);
__privateAdd(this, _projectId, void 0);
__privateAdd(this, _projectKey, void 0);
__privateAdd(this, _keys, null);
__privateAdd(this, _authorized, null);
__privateAdd(this, _user, null);
__privateAdd(this, _lock, null);
if (!/^[a-zA-Z0-9\-_]+:[a-zA-Z0-9.]+/.test(authKey)) {
throw new Error("Invalid auth key");
const [projectId, projectKey] = authKey.split(":");
const response = await fetch(
new URL(`/v1/project/${projectId}/validate`, URLS.API),
{
headers: {
[HEADER_KEYS.PROJECT_KEY]: projectKey
}
}
const [projectId, key] = authKey.split(":");
__privateSet(this, _projectId, projectId);
__privateSet(this, _projectKey, key);
__privateMethod(this, _checkProjectAuthorization, checkProjectAuthorization_fn).call(this);
);
if (!response.ok) {
throw new Error("Invalid project key");
}
get isAuthorized() {
if (__privateGet(this, _authorized) == null) {
throw new Error(
"Authorization status is not initialized, call authorize() first"
);
}
return __privateGet(this, _authorized);
}
get user() {
return structuredClone(__privateGet(this, _user));
}
get authorizationKeys() {
return structuredClone(__privateGet(this, _keys));
}
get projectId() {
return __privateGet(this, _projectId);
}
async authorize() {
await __privateGet(this, _lock);
if (assertAuthorizationsKeys(__privateGet(this, _keys))) {
const currentUserAccessKey = __privateGet(this, _keys)[COOKIES_KEYS.CURRENT_USER_ACCESS_TOKEN];
if (!currentUserAccessKey) {
__privateSet(this, _authorized, false);
__privateSet(this, _user, null);
return;
let $keys = {};
return {
setAuthorizationKeys(keys) {
$keys = keys;
},
loadBrowserAuthorizationKeys() {
if (typeof window === "undefined") {
throw new Error("This method is only available in the browser");
}
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/user/me`, URLS.API),
const cookiesNames = document.cookie.split(";").map((cookie) => {
const [name] = cookie.split("=");
return name.trim();
});
const keys = {};
for (const key of cookiesNames) {
if (!key.startsWith(COOKIES_KEYS.PREFIX))
continue;
keys[key] = import_js_cookie.default.get(key);
}
$keys = keys;
},
getProjectId() {
return projectId;
},
async getUserData(forceRefresh = false) {
const currentUserAccessKey = $keys[COOKIES_KEYS.CURRENT_USER_ACCESS_TOKEN];
if (!forceRefresh && currentUserAccessKey) {
const payloadText = currentUserAccessKey.split(".")[1];
if (payloadText) {
let payload = "null";
if (typeof window === "undefined") {
payload = Buffer.from(payloadText, "base64").toString("utf-8");
} else {
payload = atob(payloadText);
}
const payloadData = JSON.parse(payload);
if (payloadData.exp > Date.now() / 1e3) {
return { user: payloadData };
}
}
}
const currentUserRefreshKey = $keys[COOKIES_KEYS.CURRENT_USER_REFRESH_TOKEN];
if (!currentUserRefreshKey)
return {};
const response2 = await fetch(
new URL(`/v1/project/${projectId}/user/refresh`, URLS.API),
{
headers: {
Authorization: `Bearer ${currentUserAccessKey}`
Authorization: `Bearer ${currentUserRefreshKey}`
}
}
);
if (!response.ok) {
__privateSet(this, _authorized, false);
__privateSet(this, _user, null);
const { data: user, tokens } = await response2.json();
return {
user,
entries: tokens.entries
};
},
async getPublicAccessKey() {
const response2 = await fetch(
new URL(`/v1/project/${projectId}/public-access`, URLS.API),
{
credentials: "include",
headers: {
[HEADER_KEYS.PROJECT_KEY]: projectKey
}
}
);
if (!response2.ok) {
return null;
} else {
const { data: user } = await response.json();
__privateSet(this, _authorized, !!user);
__privateSet(this, _user, user);
return user;
const { data } = await response2.json();
return data;
}
}
}
loadBrowserAuthorizationKeys() {
if (typeof window === "undefined") {
throw new Error("This method is only available in the browser");
}
const cookiesNames = document.cookie.split(";").map((cookie) => {
const [name] = cookie.split("=");
return name.trim();
});
const keys = {};
for (const key of cookiesNames) {
if (!key.startsWith(COOKIES_KEYS.PREFIX))
continue;
keys[key] = import_js_cookie.default.get(key);
}
__privateSet(this, _keys, keys);
}
setAuthorizationKeys(keys) {
__privateSet(this, _keys, keys);
}
async getPublicAccessKey() {
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/public-access`, URLS.API),
{
credentials: "include",
headers: {
[HEADER_KEYS.PROJECT_KEY]: __privateGet(this, _projectKey)
},
getLogoutChainURL(projectURL) {
const domainURL = new URL(
"/logout",
`https://${projectId}.dreno.fluido.design`
);
domainURL.searchParams.set(
"from",
encodeURIComponent(projectURL.toString())
);
const apiURL = new URL(`/v1/project/${projectId}/user/logout`, URLS.API);
apiURL.searchParams.set("from", encodeURIComponent(projectURL.toString()));
return apiURL;
},
async signInWithPassword(args) {
const response2 = await fetch(
new URL(
`/v1/project/${projectId}/authentication/signin/password`,
URLS.API
),
{
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
[HEADER_KEYS.PROJECT_KEY]: projectKey
},
body: JSON.stringify(args)
}
);
if (!response2.ok) {
return null;
}
);
if (!response.ok) {
return null;
} else {
const { data } = await response.json();
return data;
}
}
async signInWithPassword(args) {
const response = await fetch(
new URL(
`/v1/project/${__privateGet(this, _projectId)}/authentication/signin/password`,
URLS.API
),
{
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
[HEADER_KEYS.PROJECT_KEY]: __privateGet(this, _projectKey)
},
body: JSON.stringify(args)
}
);
if (!response.ok) {
return null;
}
const {
tokens: { entries }
} = await response.json();
return entries;
}
async signInWithCode(code) {
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/user/refresh`, URLS.API),
{
credentials: "include",
headers: {
Authorization: `Bearer ${code}`
const {
tokens: { entries }
} = await response2.json();
return entries;
},
async signInWithCode(code) {
const response2 = await fetch(
new URL(`/v1/project/${projectId}/user/refresh`, URLS.API),
{
credentials: "include",
headers: {
Authorization: `Bearer ${code}`
}
}
);
if (!response2.ok) {
return null;
}
);
if (!response.ok) {
return null;
const {
tokens: { entries }
} = await response2.json();
return entries;
}
const {
tokens: { entries }
} = await response.json();
return entries;
}
getLogoutChainURL(projectURL) {
const domainURL = new URL(
"/logout",
`https://${this.projectId}.dreno.fluido.design`
);
domainURL.searchParams.set(
"from",
encodeURIComponent(projectURL.toString())
);
const apiURL = new URL(
`/v1/project/${this.projectId}/user/logout`,
URLS.API
);
apiURL.searchParams.set("from", encodeURIComponent(projectURL.toString()));
return apiURL;
}
};
_projectId = new WeakMap();
_projectKey = new WeakMap();
_keys = new WeakMap();
_authorized = new WeakMap();
_user = new WeakMap();
_lock = new WeakMap();
_checkProjectAuthorization = new WeakSet();
checkProjectAuthorization_fn = function() {
__privateSet(this, _lock, new Promise(async (resolve, reject) => {
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/validate`, URLS.API),
{
headers: {
[HEADER_KEYS.PROJECT_KEY]: __privateGet(this, _projectKey)
}
}
);
if (!response.ok) {
reject(new Error("Invalid project key"));
__privateSet(this, _lock, null);
return;
}
resolve();
__privateSet(this, _lock, null);
}));
};
};
}
// Annotate the CommonJS export names for ESM import in node:

@@ -468,3 +399,2 @@ 0 && (module.exports = {

DeviceCredentialSchema,
DrenoClient,
ENV_KEYS,

@@ -486,3 +416,4 @@ ExternalAccountSchema,

UserSchema,
VolatileHashSchema
VolatileHashSchema,
createDrenoClient
});

@@ -1,22 +0,22 @@

export declare class DrenoClient {
#private;
constructor(authKey: string);
get isAuthorized(): boolean;
get user(): {
id: string;
createdAt: Date;
name: string;
status: "active" | "suspended" | "deleted" | "banished";
updatedAt: Date;
lastSignInAt: Date;
imageURL?: string | undefined;
externalId?: string | undefined;
description?: string | undefined;
} | null;
get authorizationKeys(): Record<string, string | undefined> | null;
get projectId(): string;
authorize(): Promise<any>;
import type { UserData } from './schemas';
export declare function createDrenoClient(authKey: string): Promise<{
setAuthorizationKeys(keys: Record<string, string | undefined>): void;
loadBrowserAuthorizationKeys(): void;
setAuthorizationKeys(keys: Record<string, string | undefined>): void;
getProjectId(): string;
getUserData(forceRefresh?: boolean): Promise<{
user?: {
id: string;
createdAt: Date;
name: string;
status: "active" | "suspended" | "deleted" | "banished";
updatedAt: Date;
lastSignInAt: Date;
imageURL?: string | undefined;
externalId?: string | undefined;
description?: string | undefined;
} | undefined;
entries?: [string, string][] | undefined;
}>;
getPublicAccessKey(): Promise<any>;
getLogoutChainURL(projectURL: URL): URL;
signInWithPassword(args: {

@@ -27,3 +27,3 @@ identity: string;

signInWithCode(code: string): Promise<[string, string][] | null>;
getLogoutChainURL(projectURL: URL): URL;
}
}>;
export type DrenoClient = Awaited<ReturnType<typeof createDrenoClient>>;

@@ -1,24 +0,1 @@

var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var __privateMethod = (obj, member, method) => {
__accessCheck(obj, member, "access private method");
return method;
};
// src/schemas/user.ts

@@ -239,201 +216,153 @@ import {

import Cookies from "js-cookie";
// src/assertions.ts
function assertAuthorizationsKeys(keys) {
if (!keys) {
throw new Error("Authorization keys are not defined");
async function createDrenoClient(authKey) {
if (!/^[a-zA-Z0-9\-_]+:[a-zA-Z0-9.]+/.test(authKey)) {
throw new Error("Invalid auth key");
}
return true;
}
// src/client.ts
var _projectId, _projectKey, _keys, _authorized, _user, _lock, _checkProjectAuthorization, checkProjectAuthorization_fn;
var DrenoClient = class {
constructor(authKey) {
__privateAdd(this, _checkProjectAuthorization);
__privateAdd(this, _projectId, void 0);
__privateAdd(this, _projectKey, void 0);
__privateAdd(this, _keys, null);
__privateAdd(this, _authorized, null);
__privateAdd(this, _user, null);
__privateAdd(this, _lock, null);
if (!/^[a-zA-Z0-9\-_]+:[a-zA-Z0-9.]+/.test(authKey)) {
throw new Error("Invalid auth key");
const [projectId, projectKey] = authKey.split(":");
const response = await fetch(
new URL(`/v1/project/${projectId}/validate`, URLS.API),
{
headers: {
[HEADER_KEYS.PROJECT_KEY]: projectKey
}
}
const [projectId, key] = authKey.split(":");
__privateSet(this, _projectId, projectId);
__privateSet(this, _projectKey, key);
__privateMethod(this, _checkProjectAuthorization, checkProjectAuthorization_fn).call(this);
);
if (!response.ok) {
throw new Error("Invalid project key");
}
get isAuthorized() {
if (__privateGet(this, _authorized) == null) {
throw new Error(
"Authorization status is not initialized, call authorize() first"
);
}
return __privateGet(this, _authorized);
}
get user() {
return structuredClone(__privateGet(this, _user));
}
get authorizationKeys() {
return structuredClone(__privateGet(this, _keys));
}
get projectId() {
return __privateGet(this, _projectId);
}
async authorize() {
await __privateGet(this, _lock);
if (assertAuthorizationsKeys(__privateGet(this, _keys))) {
const currentUserAccessKey = __privateGet(this, _keys)[COOKIES_KEYS.CURRENT_USER_ACCESS_TOKEN];
if (!currentUserAccessKey) {
__privateSet(this, _authorized, false);
__privateSet(this, _user, null);
return;
let $keys = {};
return {
setAuthorizationKeys(keys) {
$keys = keys;
},
loadBrowserAuthorizationKeys() {
if (typeof window === "undefined") {
throw new Error("This method is only available in the browser");
}
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/user/me`, URLS.API),
const cookiesNames = document.cookie.split(";").map((cookie) => {
const [name] = cookie.split("=");
return name.trim();
});
const keys = {};
for (const key of cookiesNames) {
if (!key.startsWith(COOKIES_KEYS.PREFIX))
continue;
keys[key] = Cookies.get(key);
}
$keys = keys;
},
getProjectId() {
return projectId;
},
async getUserData(forceRefresh = false) {
const currentUserAccessKey = $keys[COOKIES_KEYS.CURRENT_USER_ACCESS_TOKEN];
if (!forceRefresh && currentUserAccessKey) {
const payloadText = currentUserAccessKey.split(".")[1];
if (payloadText) {
let payload = "null";
if (typeof window === "undefined") {
payload = Buffer.from(payloadText, "base64").toString("utf-8");
} else {
payload = atob(payloadText);
}
const payloadData = JSON.parse(payload);
if (payloadData.exp > Date.now() / 1e3) {
return { user: payloadData };
}
}
}
const currentUserRefreshKey = $keys[COOKIES_KEYS.CURRENT_USER_REFRESH_TOKEN];
if (!currentUserRefreshKey)
return {};
const response2 = await fetch(
new URL(`/v1/project/${projectId}/user/refresh`, URLS.API),
{
headers: {
Authorization: `Bearer ${currentUserAccessKey}`
Authorization: `Bearer ${currentUserRefreshKey}`
}
}
);
if (!response.ok) {
__privateSet(this, _authorized, false);
__privateSet(this, _user, null);
const { data: user, tokens } = await response2.json();
return {
user,
entries: tokens.entries
};
},
async getPublicAccessKey() {
const response2 = await fetch(
new URL(`/v1/project/${projectId}/public-access`, URLS.API),
{
credentials: "include",
headers: {
[HEADER_KEYS.PROJECT_KEY]: projectKey
}
}
);
if (!response2.ok) {
return null;
} else {
const { data: user } = await response.json();
__privateSet(this, _authorized, !!user);
__privateSet(this, _user, user);
return user;
const { data } = await response2.json();
return data;
}
}
}
loadBrowserAuthorizationKeys() {
if (typeof window === "undefined") {
throw new Error("This method is only available in the browser");
}
const cookiesNames = document.cookie.split(";").map((cookie) => {
const [name] = cookie.split("=");
return name.trim();
});
const keys = {};
for (const key of cookiesNames) {
if (!key.startsWith(COOKIES_KEYS.PREFIX))
continue;
keys[key] = Cookies.get(key);
}
__privateSet(this, _keys, keys);
}
setAuthorizationKeys(keys) {
__privateSet(this, _keys, keys);
}
async getPublicAccessKey() {
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/public-access`, URLS.API),
{
credentials: "include",
headers: {
[HEADER_KEYS.PROJECT_KEY]: __privateGet(this, _projectKey)
},
getLogoutChainURL(projectURL) {
const domainURL = new URL(
"/logout",
`https://${projectId}.dreno.fluido.design`
);
domainURL.searchParams.set(
"from",
encodeURIComponent(projectURL.toString())
);
const apiURL = new URL(`/v1/project/${projectId}/user/logout`, URLS.API);
apiURL.searchParams.set("from", encodeURIComponent(projectURL.toString()));
return apiURL;
},
async signInWithPassword(args) {
const response2 = await fetch(
new URL(
`/v1/project/${projectId}/authentication/signin/password`,
URLS.API
),
{
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
[HEADER_KEYS.PROJECT_KEY]: projectKey
},
body: JSON.stringify(args)
}
);
if (!response2.ok) {
return null;
}
);
if (!response.ok) {
return null;
} else {
const { data } = await response.json();
return data;
}
}
async signInWithPassword(args) {
const response = await fetch(
new URL(
`/v1/project/${__privateGet(this, _projectId)}/authentication/signin/password`,
URLS.API
),
{
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
[HEADER_KEYS.PROJECT_KEY]: __privateGet(this, _projectKey)
},
body: JSON.stringify(args)
}
);
if (!response.ok) {
return null;
}
const {
tokens: { entries }
} = await response.json();
return entries;
}
async signInWithCode(code) {
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/user/refresh`, URLS.API),
{
credentials: "include",
headers: {
Authorization: `Bearer ${code}`
const {
tokens: { entries }
} = await response2.json();
return entries;
},
async signInWithCode(code) {
const response2 = await fetch(
new URL(`/v1/project/${projectId}/user/refresh`, URLS.API),
{
credentials: "include",
headers: {
Authorization: `Bearer ${code}`
}
}
);
if (!response2.ok) {
return null;
}
);
if (!response.ok) {
return null;
const {
tokens: { entries }
} = await response2.json();
return entries;
}
const {
tokens: { entries }
} = await response.json();
return entries;
}
getLogoutChainURL(projectURL) {
const domainURL = new URL(
"/logout",
`https://${this.projectId}.dreno.fluido.design`
);
domainURL.searchParams.set(
"from",
encodeURIComponent(projectURL.toString())
);
const apiURL = new URL(
`/v1/project/${this.projectId}/user/logout`,
URLS.API
);
apiURL.searchParams.set("from", encodeURIComponent(projectURL.toString()));
return apiURL;
}
};
_projectId = new WeakMap();
_projectKey = new WeakMap();
_keys = new WeakMap();
_authorized = new WeakMap();
_user = new WeakMap();
_lock = new WeakMap();
_checkProjectAuthorization = new WeakSet();
checkProjectAuthorization_fn = function() {
__privateSet(this, _lock, new Promise(async (resolve, reject) => {
const response = await fetch(
new URL(`/v1/project/${__privateGet(this, _projectId)}/validate`, URLS.API),
{
headers: {
[HEADER_KEYS.PROJECT_KEY]: __privateGet(this, _projectKey)
}
}
);
if (!response.ok) {
reject(new Error("Invalid project key"));
__privateSet(this, _lock, null);
return;
}
resolve();
__privateSet(this, _lock, null);
}));
};
};
}
export {
COOKIES_KEYS,
DeviceCredentialSchema,
DrenoClient,
ENV_KEYS,

@@ -455,3 +384,4 @@ ExternalAccountSchema,

UserSchema,
VolatileHashSchema
VolatileHashSchema,
createDrenoClient
};
{
"name": "@fluido/dreno-core",
"version": "0.0.1-alpha-3",
"version": "0.0.1-alpha-4",
"description": "Dreno library",

@@ -5,0 +5,0 @@ "license": "MIT",