@secrecy/lib 1.41.0 → 1.42.1

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.
@@ -1,8 +1,8 @@
1
- import { getLink } from '@secrecy/lib-utils';
2
1
  import { usersCache } from './cache.js';
3
2
  import { getStorage } from './client/storage.js';
4
3
  import { createTRPCClient, } from './client.js';
5
4
  import { getPreferedEmail } from './utils.js';
5
+ import { getLink } from './utils/links.js';
6
6
  async function getPublicUser(client, id) {
7
7
  let user = usersCache.get(id);
8
8
  if (user !== undefined) {
@@ -0,0 +1,50 @@
1
+ export const secrecyApplications = [
2
+ 'app',
3
+ 'api',
4
+ 'auth',
5
+ 'admin',
6
+ 'dashboard',
7
+ 'me',
8
+ ];
9
+ function getEnv() {
10
+ if (typeof window === 'undefined') {
11
+ return process.env.VERCEL_ENV
12
+ ? process.env.VERCEL_ENV
13
+ : 'production';
14
+ }
15
+ if (window.location.hostname.includes('secrecy.tech')) {
16
+ return 'production';
17
+ }
18
+ if (window.location.hostname.includes('localhost')) {
19
+ return 'development';
20
+ }
21
+ if (window.location.hostname.includes('vercel.app')) {
22
+ return 'preview';
23
+ }
24
+ return 'production';
25
+ }
26
+ const env = getEnv();
27
+ const vercelUrl = process.env.VERCEL_URL ?? process.env.NEXT_PUBLIC_VERCEL_URL ?? 'secrecy.tech';
28
+ function withPath(origin, path) {
29
+ if (!path) {
30
+ return origin;
31
+ }
32
+ return `${origin.endsWith('/') ? origin : `${origin}/`}${path.startsWith('/') ? `${path.slice(1)}` : `${path}`}`;
33
+ }
34
+ function getLocalLink({ app, path, }) {
35
+ const sd = secrecyApplications.find((domain) => domain === app);
36
+ return withPath(`http://localhost:3000/${sd ?? ''}`, path);
37
+ }
38
+ function getPreviewLink({ app, path, }) {
39
+ const sd = secrecyApplications.find((domain) => domain === app);
40
+ return withPath(`https://${vercelUrl}/${sd ?? ''}`, path);
41
+ }
42
+ function getProductionLink({ app, path, }) {
43
+ const sd = secrecyApplications.find((domain) => domain === app);
44
+ return withPath(`https://${sd ? `${sd}.` : ''}${vercelUrl}`, path);
45
+ }
46
+ export const getLink = env === 'production'
47
+ ? getProductionLink
48
+ : env === 'preview'
49
+ ? getPreviewLink
50
+ : getLocalLink;
@@ -0,0 +1,9 @@
1
+ export declare const secrecyApplications: readonly ["app", "api", "auth", "admin", "dashboard", "me"];
2
+ export type VercelEnv = 'production' | 'development' | 'preview';
3
+ export type SecrecyAppSubdomain = (typeof secrecyApplications)[number];
4
+ declare function getProductionLink({ app, path, }: {
5
+ app: SecrecyAppSubdomain;
6
+ path?: string;
7
+ }): string;
8
+ export declare const getLink: typeof getProductionLink;
9
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@secrecy/lib",
3
3
  "author": "Anonymize <anonymize@gmail.com>",
4
4
  "description": "Anonymize Secrecy Library",
5
- "version": "1.41.0",
5
+ "version": "1.42.1",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/anonymize-org/lib.git"
@@ -73,7 +73,6 @@
73
73
  "typescript": "^5.5.4"
74
74
  },
75
75
  "dependencies": {
76
- "@secrecy/lib-utils": "^1.0.18",
77
76
  "@secrecy/trpc-api-types": "1.33.0-dev.13",
78
77
  "@trpc/client": "10.45.2",
79
78
  "@trpc/server": "10.45.2",