@shellapps/config 1.17.0 → 1.18.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.
- package/README.md +41 -5
- package/dist/index.d.mts +43 -1
- package/dist/index.d.ts +43 -1
- package/dist/index.js +90 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -5
- package/src/config.ts +144 -0
- package/src/core-nav.ts +136 -0
- package/src/index.ts +32 -138
package/README.md
CHANGED
|
@@ -51,10 +51,11 @@ const env = getEnvironment(); // 'development' | 'staging' | 'production'
|
|
|
51
51
|
|
|
52
52
|
// Get service URLs
|
|
53
53
|
const urls = getServiceUrls();
|
|
54
|
-
console.log(urls.auth);
|
|
55
|
-
console.log(urls.apps);
|
|
56
|
-
console.log(urls.blog);
|
|
57
|
-
console.log(urls.admin);
|
|
54
|
+
console.log(urls.auth); // Auth service URL (ShellApps ID)
|
|
55
|
+
console.log(urls.apps); // Main apps URL (launcher / store)
|
|
56
|
+
console.log(urls.blog); // Blog URL
|
|
57
|
+
console.log(urls.admin); // ShellLabs admin URL
|
|
58
|
+
console.log(urls.payments); // Payments URL
|
|
58
59
|
|
|
59
60
|
// Get S3 configuration
|
|
60
61
|
const s3 = getS3Config();
|
|
@@ -81,6 +82,35 @@ const serviceUrls = config.getServiceUrls();
|
|
|
81
82
|
const s3Config = config.getS3Config();
|
|
82
83
|
```
|
|
83
84
|
|
|
85
|
+
### Core Navigation
|
|
86
|
+
|
|
87
|
+
The three core ShellApps apps — `apps.shellapps.com` (launcher / store),
|
|
88
|
+
`auth.shellapps.com` (ShellApps ID) and `payments.shellapps.com` — render the
|
|
89
|
+
same flat sidebar nav. This package owns that list as pure data: no React, no
|
|
90
|
+
icons, just links and helpers. Each app supplies its own presentation.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { getCoreNav, isCurrentCoreLink, markCurrentCoreNav } from '@shellapps/config';
|
|
94
|
+
|
|
95
|
+
// A flat list of 21 links in render order, with absolute hrefs resolved
|
|
96
|
+
// against the current environment's service URLs.
|
|
97
|
+
const nav = getCoreNav();
|
|
98
|
+
nav[1]; // { key: 'store', name: 'Store', href: 'https://apps.shellapps.com/store', app: 'apps' }
|
|
99
|
+
|
|
100
|
+
// Is this link the page we are on?
|
|
101
|
+
isCurrentCoreLink(nav[1], 'https://apps.shellapps.com', '/store'); // true
|
|
102
|
+
|
|
103
|
+
// Or annotate the whole list at once (pure — the input is never mutated).
|
|
104
|
+
const marked = markCurrentCoreNav(nav, window.location.origin, window.location.pathname);
|
|
105
|
+
marked[1]; // { ...link, current: true }
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Matching rules for `isCurrentCoreLink` / `markCurrentCoreNav`:
|
|
109
|
+
|
|
110
|
+
- Origins compare case-insensitively, ignoring trailing slashes.
|
|
111
|
+
- Paths compare with a trailing slash treated as insignificant (`/store/` === `/store`).
|
|
112
|
+
- The root link (`apps`) matches only the root path.
|
|
113
|
+
|
|
84
114
|
### TypeScript Types
|
|
85
115
|
|
|
86
116
|
All configuration objects are fully typed:
|
|
@@ -92,7 +122,10 @@ import type {
|
|
|
92
122
|
ServiceUrls,
|
|
93
123
|
S3Config,
|
|
94
124
|
MongoConfig,
|
|
95
|
-
FeatureFlags
|
|
125
|
+
FeatureFlags,
|
|
126
|
+
CoreNavApp,
|
|
127
|
+
CoreNavLink,
|
|
128
|
+
CoreNavLinkWithCurrent
|
|
96
129
|
} from '@shellapps/config';
|
|
97
130
|
|
|
98
131
|
function setupApp(config: Config) {
|
|
@@ -159,6 +192,9 @@ npm install
|
|
|
159
192
|
# Build the package
|
|
160
193
|
npm run build
|
|
161
194
|
|
|
195
|
+
# Run the tests
|
|
196
|
+
npm test
|
|
197
|
+
|
|
162
198
|
# Watch for changes during development
|
|
163
199
|
npm run dev
|
|
164
200
|
|
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ interface ServiceUrls {
|
|
|
5
5
|
blog: string;
|
|
6
6
|
engineering: string;
|
|
7
7
|
admin: string;
|
|
8
|
+
payments: string;
|
|
8
9
|
}
|
|
9
10
|
interface S3Config {
|
|
10
11
|
buckets: {
|
|
@@ -33,6 +34,44 @@ declare function getServiceUrls(): ServiceUrls;
|
|
|
33
34
|
declare function getS3Config(): S3Config;
|
|
34
35
|
declare function getMongoConfig(): MongoConfig;
|
|
35
36
|
declare function getFeatureFlags(): FeatureFlags;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The three core ShellApps apps that own a slice of the shared core nav.
|
|
40
|
+
* Each maps to a key on {@link ServiceUrls}, so a link's origin is resolved
|
|
41
|
+
* per environment (development / staging / production).
|
|
42
|
+
*/
|
|
43
|
+
type CoreNavApp = 'apps' | 'auth' | 'payments';
|
|
44
|
+
/**
|
|
45
|
+
* One entry in the shared core nav. `href` is always absolute — the owning
|
|
46
|
+
* app's origin for the current environment, plus the entry's path.
|
|
47
|
+
*/
|
|
48
|
+
interface CoreNavLink {
|
|
49
|
+
key: string;
|
|
50
|
+
name: string;
|
|
51
|
+
href: string;
|
|
52
|
+
app: CoreNavApp;
|
|
53
|
+
}
|
|
54
|
+
/** A {@link CoreNavLink} annotated with whether it is the current location. */
|
|
55
|
+
type CoreNavLinkWithCurrent = CoreNavLink & {
|
|
56
|
+
current: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The shared core nav for the current environment: a flat list of absolute
|
|
60
|
+
* links, in render order.
|
|
61
|
+
*/
|
|
62
|
+
declare function getCoreNav(): CoreNavLink[];
|
|
63
|
+
/**
|
|
64
|
+
* Whether `link` points at the location described by `currentOrigin` /
|
|
65
|
+
* `currentPath`. Origins compare case-insensitively and ignore trailing
|
|
66
|
+
* slashes; paths compare with a trailing slash treated as insignificant.
|
|
67
|
+
*/
|
|
68
|
+
declare function isCurrentCoreLink(link: CoreNavLink, currentOrigin: string, currentPath: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Annotate every link with whether it is the current one. Pure — the input
|
|
71
|
+
* array and its links are never mutated.
|
|
72
|
+
*/
|
|
73
|
+
declare function markCurrentCoreNav(nav: CoreNavLink[], currentOrigin: string, currentPath: string): CoreNavLinkWithCurrent[];
|
|
74
|
+
|
|
36
75
|
declare const _default: {
|
|
37
76
|
getConfig: typeof getConfig;
|
|
38
77
|
getEnvironment: typeof getEnvironment;
|
|
@@ -40,6 +79,9 @@ declare const _default: {
|
|
|
40
79
|
getS3Config: typeof getS3Config;
|
|
41
80
|
getMongoConfig: typeof getMongoConfig;
|
|
42
81
|
getFeatureFlags: typeof getFeatureFlags;
|
|
82
|
+
getCoreNav: typeof getCoreNav;
|
|
83
|
+
isCurrentCoreLink: typeof isCurrentCoreLink;
|
|
84
|
+
markCurrentCoreNav: typeof markCurrentCoreNav;
|
|
43
85
|
};
|
|
44
86
|
|
|
45
|
-
export { type Config, type Environment, type FeatureFlags, type MongoConfig, type S3Config, type ServiceUrls, _default as default, getConfig, getEnvironment, getFeatureFlags, getMongoConfig, getS3Config, getServiceUrls };
|
|
87
|
+
export { type Config, type CoreNavApp, type CoreNavLink, type CoreNavLinkWithCurrent, type Environment, type FeatureFlags, type MongoConfig, type S3Config, type ServiceUrls, _default as default, getConfig, getCoreNav, getEnvironment, getFeatureFlags, getMongoConfig, getS3Config, getServiceUrls, isCurrentCoreLink, markCurrentCoreNav };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ interface ServiceUrls {
|
|
|
5
5
|
blog: string;
|
|
6
6
|
engineering: string;
|
|
7
7
|
admin: string;
|
|
8
|
+
payments: string;
|
|
8
9
|
}
|
|
9
10
|
interface S3Config {
|
|
10
11
|
buckets: {
|
|
@@ -33,6 +34,44 @@ declare function getServiceUrls(): ServiceUrls;
|
|
|
33
34
|
declare function getS3Config(): S3Config;
|
|
34
35
|
declare function getMongoConfig(): MongoConfig;
|
|
35
36
|
declare function getFeatureFlags(): FeatureFlags;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The three core ShellApps apps that own a slice of the shared core nav.
|
|
40
|
+
* Each maps to a key on {@link ServiceUrls}, so a link's origin is resolved
|
|
41
|
+
* per environment (development / staging / production).
|
|
42
|
+
*/
|
|
43
|
+
type CoreNavApp = 'apps' | 'auth' | 'payments';
|
|
44
|
+
/**
|
|
45
|
+
* One entry in the shared core nav. `href` is always absolute — the owning
|
|
46
|
+
* app's origin for the current environment, plus the entry's path.
|
|
47
|
+
*/
|
|
48
|
+
interface CoreNavLink {
|
|
49
|
+
key: string;
|
|
50
|
+
name: string;
|
|
51
|
+
href: string;
|
|
52
|
+
app: CoreNavApp;
|
|
53
|
+
}
|
|
54
|
+
/** A {@link CoreNavLink} annotated with whether it is the current location. */
|
|
55
|
+
type CoreNavLinkWithCurrent = CoreNavLink & {
|
|
56
|
+
current: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The shared core nav for the current environment: a flat list of absolute
|
|
60
|
+
* links, in render order.
|
|
61
|
+
*/
|
|
62
|
+
declare function getCoreNav(): CoreNavLink[];
|
|
63
|
+
/**
|
|
64
|
+
* Whether `link` points at the location described by `currentOrigin` /
|
|
65
|
+
* `currentPath`. Origins compare case-insensitively and ignore trailing
|
|
66
|
+
* slashes; paths compare with a trailing slash treated as insignificant.
|
|
67
|
+
*/
|
|
68
|
+
declare function isCurrentCoreLink(link: CoreNavLink, currentOrigin: string, currentPath: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Annotate every link with whether it is the current one. Pure — the input
|
|
71
|
+
* array and its links are never mutated.
|
|
72
|
+
*/
|
|
73
|
+
declare function markCurrentCoreNav(nav: CoreNavLink[], currentOrigin: string, currentPath: string): CoreNavLinkWithCurrent[];
|
|
74
|
+
|
|
36
75
|
declare const _default: {
|
|
37
76
|
getConfig: typeof getConfig;
|
|
38
77
|
getEnvironment: typeof getEnvironment;
|
|
@@ -40,6 +79,9 @@ declare const _default: {
|
|
|
40
79
|
getS3Config: typeof getS3Config;
|
|
41
80
|
getMongoConfig: typeof getMongoConfig;
|
|
42
81
|
getFeatureFlags: typeof getFeatureFlags;
|
|
82
|
+
getCoreNav: typeof getCoreNav;
|
|
83
|
+
isCurrentCoreLink: typeof isCurrentCoreLink;
|
|
84
|
+
markCurrentCoreNav: typeof markCurrentCoreNav;
|
|
43
85
|
};
|
|
44
86
|
|
|
45
|
-
export { type Config, type Environment, type FeatureFlags, type MongoConfig, type S3Config, type ServiceUrls, _default as default, getConfig, getEnvironment, getFeatureFlags, getMongoConfig, getS3Config, getServiceUrls };
|
|
87
|
+
export { type Config, type CoreNavApp, type CoreNavLink, type CoreNavLinkWithCurrent, type Environment, type FeatureFlags, type MongoConfig, type S3Config, type ServiceUrls, _default as default, getConfig, getCoreNav, getEnvironment, getFeatureFlags, getMongoConfig, getS3Config, getServiceUrls, isCurrentCoreLink, markCurrentCoreNav };
|
package/dist/index.js
CHANGED
|
@@ -22,13 +22,18 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
default: () => index_default,
|
|
24
24
|
getConfig: () => getConfig,
|
|
25
|
+
getCoreNav: () => getCoreNav,
|
|
25
26
|
getEnvironment: () => getEnvironment,
|
|
26
27
|
getFeatureFlags: () => getFeatureFlags,
|
|
27
28
|
getMongoConfig: () => getMongoConfig,
|
|
28
29
|
getS3Config: () => getS3Config,
|
|
29
|
-
getServiceUrls: () => getServiceUrls
|
|
30
|
+
getServiceUrls: () => getServiceUrls,
|
|
31
|
+
isCurrentCoreLink: () => isCurrentCoreLink,
|
|
32
|
+
markCurrentCoreNav: () => markCurrentCoreNav
|
|
30
33
|
});
|
|
31
34
|
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
|
|
36
|
+
// src/config.ts
|
|
32
37
|
var configs = {
|
|
33
38
|
development: {
|
|
34
39
|
environment: "development",
|
|
@@ -37,8 +42,9 @@ var configs = {
|
|
|
37
42
|
apps: "http://localhost:3000",
|
|
38
43
|
blog: "http://localhost:3002",
|
|
39
44
|
engineering: "http://localhost:3003",
|
|
40
|
-
admin: "http://localhost:3004"
|
|
45
|
+
admin: "http://localhost:3004",
|
|
41
46
|
// ShellLabs admin
|
|
47
|
+
payments: "http://localhost:3003"
|
|
42
48
|
},
|
|
43
49
|
s3: {
|
|
44
50
|
buckets: {
|
|
@@ -58,12 +64,13 @@ var configs = {
|
|
|
58
64
|
staging: {
|
|
59
65
|
environment: "staging",
|
|
60
66
|
serviceUrls: {
|
|
61
|
-
auth: "https://auth.
|
|
67
|
+
auth: "https://auth.shellapps.net",
|
|
62
68
|
apps: "https://apps.shellapps.net",
|
|
63
69
|
blog: "https://blog.shellapps.net",
|
|
64
70
|
engineering: "https://engineering.shellapps.net",
|
|
65
|
-
admin: "https://admin.shelllabs.net"
|
|
71
|
+
admin: "https://admin.shelllabs.net",
|
|
66
72
|
// ShellLabs admin
|
|
73
|
+
payments: "https://payments.shellapps.net"
|
|
67
74
|
},
|
|
68
75
|
s3: {
|
|
69
76
|
buckets: {
|
|
@@ -83,12 +90,13 @@ var configs = {
|
|
|
83
90
|
production: {
|
|
84
91
|
environment: "production",
|
|
85
92
|
serviceUrls: {
|
|
86
|
-
auth: "https://auth.
|
|
93
|
+
auth: "https://auth.shellapps.com",
|
|
87
94
|
apps: "https://apps.shellapps.com",
|
|
88
95
|
blog: "https://blog.shellapps.com",
|
|
89
96
|
engineering: "https://engineering.shellapps.com",
|
|
90
|
-
admin: "https://admin.shelllabs.net"
|
|
97
|
+
admin: "https://admin.shelllabs.net",
|
|
91
98
|
// ShellLabs admin
|
|
99
|
+
payments: "https://payments.shellapps.com"
|
|
92
100
|
},
|
|
93
101
|
s3: {
|
|
94
102
|
buckets: {
|
|
@@ -128,21 +136,95 @@ function getMongoConfig() {
|
|
|
128
136
|
function getFeatureFlags() {
|
|
129
137
|
return getConfig().featureFlags;
|
|
130
138
|
}
|
|
139
|
+
|
|
140
|
+
// src/core-nav.ts
|
|
141
|
+
var CORE_NAV_ENTRIES = [
|
|
142
|
+
{ key: "apps", name: "Apps", app: "apps", path: "/" },
|
|
143
|
+
{ key: "store", name: "Store", app: "apps", path: "/store" },
|
|
144
|
+
{ key: "profile", name: "Profile", app: "auth", path: "/profile" },
|
|
145
|
+
{ key: "profiles", name: "Profiles", app: "auth", path: "/profiles" },
|
|
146
|
+
{ key: "groups", name: "Groups", app: "auth", path: "/groups" },
|
|
147
|
+
{ key: "data", name: "Data", app: "auth", path: "/data" },
|
|
148
|
+
{ key: "network", name: "Network", app: "auth", path: "/network" },
|
|
149
|
+
{ key: "feedback", name: "Feedback", app: "auth", path: "/feedback" },
|
|
150
|
+
{ key: "privacy", name: "Privacy", app: "auth", path: "/settings/privacy" },
|
|
151
|
+
{ key: "security", name: "Security", app: "auth", path: "/settings/security" },
|
|
152
|
+
{ key: "permissions", name: "Permissions", app: "auth", path: "/settings/permissions" },
|
|
153
|
+
{ key: "appearance", name: "Appearance", app: "auth", path: "/settings/appearance" },
|
|
154
|
+
{ key: "builder-tools", name: "Builder Tools", app: "auth", path: "/settings/builder" },
|
|
155
|
+
{ key: "api-keys", name: "API Keys", app: "auth", path: "/settings/builder/keys" },
|
|
156
|
+
{ key: "subscriptions", name: "Subscriptions", app: "payments", path: "/subscriptions" },
|
|
157
|
+
{ key: "purchases", name: "Purchases", app: "payments", path: "/purchases" },
|
|
158
|
+
{ key: "invoices", name: "Invoices", app: "payments", path: "/invoices" },
|
|
159
|
+
{ key: "tokens", name: "Tokens", app: "payments", path: "/tokens" },
|
|
160
|
+
{ key: "usage", name: "Usage", app: "payments", path: "/usage" },
|
|
161
|
+
{ key: "payment-methods", name: "Payment Methods", app: "payments", path: "/payment-methods" },
|
|
162
|
+
{ key: "payment-settings", name: "Payment Settings", app: "payments", path: "/settings" }
|
|
163
|
+
];
|
|
164
|
+
function stripTrailingSlashes(origin) {
|
|
165
|
+
return origin.replace(/\/+$/, "");
|
|
166
|
+
}
|
|
167
|
+
function normalisePath(path) {
|
|
168
|
+
const trimmed = path.replace(/\/+$/, "");
|
|
169
|
+
return trimmed === "" ? "/" : trimmed;
|
|
170
|
+
}
|
|
171
|
+
var ORIGIN_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/[^/?#]*)(.*)$/i;
|
|
172
|
+
function splitHref(href) {
|
|
173
|
+
const match = ORIGIN_PATTERN.exec(href);
|
|
174
|
+
if (!match) {
|
|
175
|
+
return { origin: "", path: href.split(/[?#]/)[0] || "/" };
|
|
176
|
+
}
|
|
177
|
+
const rest = match[2];
|
|
178
|
+
const path = (rest ? rest.split(/[?#]/)[0] : "") || "/";
|
|
179
|
+
return { origin: match[1], path };
|
|
180
|
+
}
|
|
181
|
+
function getCoreNav() {
|
|
182
|
+
const serviceUrls = getServiceUrls();
|
|
183
|
+
return CORE_NAV_ENTRIES.map((entry) => ({
|
|
184
|
+
key: entry.key,
|
|
185
|
+
name: entry.name,
|
|
186
|
+
app: entry.app,
|
|
187
|
+
href: `${stripTrailingSlashes(serviceUrls[entry.app])}${entry.path}`
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
function isCurrentCoreLink(link, currentOrigin, currentPath) {
|
|
191
|
+
const { origin, path } = splitHref(link.href);
|
|
192
|
+
const linkOrigin = stripTrailingSlashes(origin).toLowerCase();
|
|
193
|
+
const otherOrigin = stripTrailingSlashes(currentOrigin).toLowerCase();
|
|
194
|
+
if (linkOrigin !== otherOrigin) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
return normalisePath(path) === normalisePath(currentPath);
|
|
198
|
+
}
|
|
199
|
+
function markCurrentCoreNav(nav, currentOrigin, currentPath) {
|
|
200
|
+
return nav.map((link) => ({
|
|
201
|
+
...link,
|
|
202
|
+
current: isCurrentCoreLink(link, currentOrigin, currentPath)
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/index.ts
|
|
131
207
|
var index_default = {
|
|
132
208
|
getConfig,
|
|
133
209
|
getEnvironment,
|
|
134
210
|
getServiceUrls,
|
|
135
211
|
getS3Config,
|
|
136
212
|
getMongoConfig,
|
|
137
|
-
getFeatureFlags
|
|
213
|
+
getFeatureFlags,
|
|
214
|
+
getCoreNav,
|
|
215
|
+
isCurrentCoreLink,
|
|
216
|
+
markCurrentCoreNav
|
|
138
217
|
};
|
|
139
218
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
219
|
0 && (module.exports = {
|
|
141
220
|
getConfig,
|
|
221
|
+
getCoreNav,
|
|
142
222
|
getEnvironment,
|
|
143
223
|
getFeatureFlags,
|
|
144
224
|
getMongoConfig,
|
|
145
225
|
getS3Config,
|
|
146
|
-
getServiceUrls
|
|
226
|
+
getServiceUrls,
|
|
227
|
+
isCurrentCoreLink,
|
|
228
|
+
markCurrentCoreNav
|
|
147
229
|
});
|
|
148
230
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type Environment = 'development' | 'staging' | 'production';\n\nexport interface ServiceUrls {\n auth: string;\n apps: string;\n blog: string;\n engineering: string;\n admin: string; // ShellLabs\n}\n\nexport interface S3Config {\n buckets: {\n assets: string;\n uploads: string;\n backups: string;\n };\n}\n\nexport interface MongoConfig {\n database: string;\n authDatabase?: string;\n}\n\nexport interface FeatureFlags {\n [key: string]: boolean;\n}\n\nexport interface Config {\n environment: Environment;\n serviceUrls: ServiceUrls;\n s3: S3Config;\n mongodb: MongoConfig;\n featureFlags: FeatureFlags;\n}\n\nconst configs: Record<Environment, Config> = {\n development: {\n environment: 'development',\n serviceUrls: {\n auth: 'http://localhost:3001',\n apps: 'http://localhost:3000',\n blog: 'http://localhost:3002',\n engineering: 'http://localhost:3003',\n admin: 'http://localhost:3004', // ShellLabs admin\n },\n s3: {\n buckets: {\n assets: 'shellapps-dev-assets',\n uploads: 'shellapps-dev-uploads',\n backups: 'shellapps-dev-backups',\n },\n },\n mongodb: {\n database: 'shellapps_dev',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n staging: {\n environment: 'staging',\n serviceUrls: {\n auth: 'https://auth.shelllabs.net',\n apps: 'https://apps.shellapps.net',\n blog: 'https://blog.shellapps.net',\n engineering: 'https://engineering.shellapps.net',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n },\n s3: {\n buckets: {\n assets: 'shellapps-staging-assets',\n uploads: 'shellapps-staging-uploads',\n backups: 'shellapps-staging-backups',\n },\n },\n mongodb: {\n database: 'shellapps_staging',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n production: {\n environment: 'production',\n serviceUrls: {\n auth: 'https://auth.shelllabs.net',\n apps: 'https://apps.shellapps.com',\n blog: 'https://blog.shellapps.com',\n engineering: 'https://engineering.shellapps.com',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n },\n s3: {\n buckets: {\n assets: 'shellapps-prod-assets',\n uploads: 'shellapps-prod-uploads',\n backups: 'shellapps-prod-backups',\n },\n },\n mongodb: {\n database: 'shellapps_production',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n};\n\nexport function getConfig(): Config {\n const env = (process.env.SHELLAPPS_ENV || 'development') as Environment;\n \n if (!configs[env]) {\n throw new Error(`Invalid environment: ${env}. Must be one of: development, staging, production`);\n }\n \n return configs[env];\n}\n\n// Export individual getters for convenience\nexport function getEnvironment(): Environment {\n return getConfig().environment;\n}\n\nexport function getServiceUrls(): ServiceUrls {\n return getConfig().serviceUrls;\n}\n\nexport function getS3Config(): S3Config {\n return getConfig().s3;\n}\n\nexport function getMongoConfig(): MongoConfig {\n return getConfig().mongodb;\n}\n\nexport function getFeatureFlags(): FeatureFlags {\n return getConfig().featureFlags;\n}\n\n// Default export\nexport default {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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AAQ,GAAG,GAAG;AACjB,UAAM,IAAI,MAAM,wBAAwB,GAAG,oDAAoD;AAAA,EACjG;AAEA,SAAO,QAAQ,GAAG;AACpB;AAGO,SAAS,iBAA8B;AAC5C,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,iBAA8B;AAC5C,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,cAAwB;AACtC,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,iBAA8B;AAC5C,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,kBAAgC;AAC9C,SAAO,UAAU,EAAE;AACrB;AAGA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/core-nav.ts"],"sourcesContent":["export type {\n Environment,\n ServiceUrls,\n S3Config,\n MongoConfig,\n FeatureFlags,\n Config,\n} from './config';\n\nexport {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n} from './config';\n\nexport type { CoreNavApp, CoreNavLink, CoreNavLinkWithCurrent } from './core-nav';\n\nexport { getCoreNav, isCurrentCoreLink, markCurrentCoreNav } from './core-nav';\n\nimport {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n} from './config';\nimport { getCoreNav, isCurrentCoreLink, markCurrentCoreNav } from './core-nav';\n\n// Default export\nexport default {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n getCoreNav,\n isCurrentCoreLink,\n markCurrentCoreNav,\n};\n","export type Environment = 'development' | 'staging' | 'production';\n\nexport interface ServiceUrls {\n auth: string;\n apps: string;\n blog: string;\n engineering: string;\n admin: string; // ShellLabs\n payments: string;\n}\n\nexport interface S3Config {\n buckets: {\n assets: string;\n uploads: string;\n backups: string;\n };\n}\n\nexport interface MongoConfig {\n database: string;\n authDatabase?: string;\n}\n\nexport interface FeatureFlags {\n [key: string]: boolean;\n}\n\nexport interface Config {\n environment: Environment;\n serviceUrls: ServiceUrls;\n s3: S3Config;\n mongodb: MongoConfig;\n featureFlags: FeatureFlags;\n}\n\nconst configs: Record<Environment, Config> = {\n development: {\n environment: 'development',\n serviceUrls: {\n auth: 'http://localhost:3001',\n apps: 'http://localhost:3000',\n blog: 'http://localhost:3002',\n engineering: 'http://localhost:3003',\n admin: 'http://localhost:3004', // ShellLabs admin\n payments: 'http://localhost:3003',\n },\n s3: {\n buckets: {\n assets: 'shellapps-dev-assets',\n uploads: 'shellapps-dev-uploads',\n backups: 'shellapps-dev-backups',\n },\n },\n mongodb: {\n database: 'shellapps_dev',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n staging: {\n environment: 'staging',\n serviceUrls: {\n auth: 'https://auth.shellapps.net',\n apps: 'https://apps.shellapps.net',\n blog: 'https://blog.shellapps.net',\n engineering: 'https://engineering.shellapps.net',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n payments: 'https://payments.shellapps.net',\n },\n s3: {\n buckets: {\n assets: 'shellapps-staging-assets',\n uploads: 'shellapps-staging-uploads',\n backups: 'shellapps-staging-backups',\n },\n },\n mongodb: {\n database: 'shellapps_staging',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n production: {\n environment: 'production',\n serviceUrls: {\n auth: 'https://auth.shellapps.com',\n apps: 'https://apps.shellapps.com',\n blog: 'https://blog.shellapps.com',\n engineering: 'https://engineering.shellapps.com',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n payments: 'https://payments.shellapps.com',\n },\n s3: {\n buckets: {\n assets: 'shellapps-prod-assets',\n uploads: 'shellapps-prod-uploads',\n backups: 'shellapps-prod-backups',\n },\n },\n mongodb: {\n database: 'shellapps_production',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n};\n\nexport function getConfig(): Config {\n const env = (process.env.SHELLAPPS_ENV || 'development') as Environment;\n \n if (!configs[env]) {\n throw new Error(`Invalid environment: ${env}. Must be one of: development, staging, production`);\n }\n \n return configs[env];\n}\n\n// Export individual getters for convenience\nexport function getEnvironment(): Environment {\n return getConfig().environment;\n}\n\nexport function getServiceUrls(): ServiceUrls {\n return getConfig().serviceUrls;\n}\n\nexport function getS3Config(): S3Config {\n return getConfig().s3;\n}\n\nexport function getMongoConfig(): MongoConfig {\n return getConfig().mongodb;\n}\n\nexport function getFeatureFlags(): FeatureFlags {\n return getConfig().featureFlags;\n}\n","import { getServiceUrls } from './config';\n\n/**\n * The three core ShellApps apps that own a slice of the shared core nav.\n * Each maps to a key on {@link ServiceUrls}, so a link's origin is resolved\n * per environment (development / staging / production).\n */\nexport type CoreNavApp = 'apps' | 'auth' | 'payments';\n\n/**\n * One entry in the shared core nav. `href` is always absolute — the owning\n * app's origin for the current environment, plus the entry's path.\n */\nexport interface CoreNavLink {\n key: string;\n name: string;\n href: string;\n app: CoreNavApp;\n}\n\n/** A {@link CoreNavLink} annotated with whether it is the current location. */\nexport type CoreNavLinkWithCurrent = CoreNavLink & { current: boolean };\n\ninterface CoreNavEntry {\n key: string;\n name: string;\n app: CoreNavApp;\n path: string;\n}\n\n/**\n * The flat core nav, in render order. Shared verbatim by apps.shellapps.com,\n * auth.shellapps.com and payments.shellapps.com — each renders the same list,\n * so ordering here is the ordering everywhere.\n */\nconst CORE_NAV_ENTRIES: readonly CoreNavEntry[] = [\n { key: 'apps', name: 'Apps', app: 'apps', path: '/' },\n { key: 'store', name: 'Store', app: 'apps', path: '/store' },\n { key: 'profile', name: 'Profile', app: 'auth', path: '/profile' },\n { key: 'profiles', name: 'Profiles', app: 'auth', path: '/profiles' },\n { key: 'groups', name: 'Groups', app: 'auth', path: '/groups' },\n { key: 'data', name: 'Data', app: 'auth', path: '/data' },\n { key: 'network', name: 'Network', app: 'auth', path: '/network' },\n { key: 'feedback', name: 'Feedback', app: 'auth', path: '/feedback' },\n { key: 'privacy', name: 'Privacy', app: 'auth', path: '/settings/privacy' },\n { key: 'security', name: 'Security', app: 'auth', path: '/settings/security' },\n { key: 'permissions', name: 'Permissions', app: 'auth', path: '/settings/permissions' },\n { key: 'appearance', name: 'Appearance', app: 'auth', path: '/settings/appearance' },\n { key: 'builder-tools', name: 'Builder Tools', app: 'auth', path: '/settings/builder' },\n { key: 'api-keys', name: 'API Keys', app: 'auth', path: '/settings/builder/keys' },\n { key: 'subscriptions', name: 'Subscriptions', app: 'payments', path: '/subscriptions' },\n { key: 'purchases', name: 'Purchases', app: 'payments', path: '/purchases' },\n { key: 'invoices', name: 'Invoices', app: 'payments', path: '/invoices' },\n { key: 'tokens', name: 'Tokens', app: 'payments', path: '/tokens' },\n { key: 'usage', name: 'Usage', app: 'payments', path: '/usage' },\n { key: 'payment-methods', name: 'Payment Methods', app: 'payments', path: '/payment-methods' },\n { key: 'payment-settings', name: 'Payment Settings', app: 'payments', path: '/settings' },\n];\n\n/** Strip any trailing slashes so an origin never double-slashes into a path. */\nfunction stripTrailingSlashes(origin: string): string {\n return origin.replace(/\\/+$/, '');\n}\n\n/**\n * Normalise a path for comparison: a trailing slash is insignificant\n * (`/store/` === `/store`), except at the root, which stays `/`.\n */\nfunction normalisePath(path: string): string {\n const trimmed = path.replace(/\\/+$/, '');\n return trimmed === '' ? '/' : trimmed;\n}\n\nconst ORIGIN_PATTERN = /^([a-z][a-z0-9+.-]*:\\/\\/[^/?#]*)(.*)$/i;\n\n/** Split an absolute href into its origin and path, framework-free. */\nfunction splitHref(href: string): { origin: string; path: string } {\n const match = ORIGIN_PATTERN.exec(href);\n if (!match) {\n return { origin: '', path: href.split(/[?#]/)[0] || '/' };\n }\n const rest = match[2];\n const path = (rest ? rest.split(/[?#]/)[0] : '') || '/';\n return { origin: match[1], path };\n}\n\n/**\n * The shared core nav for the current environment: a flat list of absolute\n * links, in render order.\n */\nexport function getCoreNav(): CoreNavLink[] {\n const serviceUrls = getServiceUrls();\n\n return CORE_NAV_ENTRIES.map((entry) => ({\n key: entry.key,\n name: entry.name,\n app: entry.app,\n href: `${stripTrailingSlashes(serviceUrls[entry.app])}${entry.path}`,\n }));\n}\n\n/**\n * Whether `link` points at the location described by `currentOrigin` /\n * `currentPath`. Origins compare case-insensitively and ignore trailing\n * slashes; paths compare with a trailing slash treated as insignificant.\n */\nexport function isCurrentCoreLink(\n link: CoreNavLink,\n currentOrigin: string,\n currentPath: string\n): boolean {\n const { origin, path } = splitHref(link.href);\n\n const linkOrigin = stripTrailingSlashes(origin).toLowerCase();\n const otherOrigin = stripTrailingSlashes(currentOrigin).toLowerCase();\n if (linkOrigin !== otherOrigin) {\n return false;\n }\n\n return normalisePath(path) === normalisePath(currentPath);\n}\n\n/**\n * Annotate every link with whether it is the current one. Pure — the input\n * array and its links are never mutated.\n */\nexport function markCurrentCoreNav(\n nav: CoreNavLink[],\n currentOrigin: string,\n currentPath: string\n): CoreNavLinkWithCurrent[] {\n return nav.map((link) => ({\n ...link,\n current: isCurrentCoreLink(link, currentOrigin, currentPath),\n }));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoCA,IAAM,UAAuC;AAAA,EAC3C,aAAa;AAAA,IACX,aAAa;AAAA,IACb,aAAa;AAAA,MACX,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,MACb,OAAO;AAAA;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,IACA,IAAI;AAAA,MACF,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,UAAU;AAAA,MACV,cAAc;AAAA,IAChB;AAAA,IACA,cAAc;AAAA;AAAA,IAEd;AAAA,EACF;AAAA,EACA,SAAS;AAAA,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,EACT;AAEA,SAAO,cAAc,IAAI,MAAM,cAAc,WAAW;AAC1D;AAMO,SAAS,mBACd,KACA,eACA,aAC0B;AAC1B,SAAO,IAAI,IAAI,CAAC,UAAU;AAAA,IACxB,GAAG;AAAA,IACH,SAAS,kBAAkB,MAAM,eAAe,WAAW;AAAA,EAC7D,EAAE;AACJ;;;AFtGA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/config.ts
|
|
2
2
|
var configs = {
|
|
3
3
|
development: {
|
|
4
4
|
environment: "development",
|
|
@@ -7,8 +7,9 @@ var configs = {
|
|
|
7
7
|
apps: "http://localhost:3000",
|
|
8
8
|
blog: "http://localhost:3002",
|
|
9
9
|
engineering: "http://localhost:3003",
|
|
10
|
-
admin: "http://localhost:3004"
|
|
10
|
+
admin: "http://localhost:3004",
|
|
11
11
|
// ShellLabs admin
|
|
12
|
+
payments: "http://localhost:3003"
|
|
12
13
|
},
|
|
13
14
|
s3: {
|
|
14
15
|
buckets: {
|
|
@@ -28,12 +29,13 @@ var configs = {
|
|
|
28
29
|
staging: {
|
|
29
30
|
environment: "staging",
|
|
30
31
|
serviceUrls: {
|
|
31
|
-
auth: "https://auth.
|
|
32
|
+
auth: "https://auth.shellapps.net",
|
|
32
33
|
apps: "https://apps.shellapps.net",
|
|
33
34
|
blog: "https://blog.shellapps.net",
|
|
34
35
|
engineering: "https://engineering.shellapps.net",
|
|
35
|
-
admin: "https://admin.shelllabs.net"
|
|
36
|
+
admin: "https://admin.shelllabs.net",
|
|
36
37
|
// ShellLabs admin
|
|
38
|
+
payments: "https://payments.shellapps.net"
|
|
37
39
|
},
|
|
38
40
|
s3: {
|
|
39
41
|
buckets: {
|
|
@@ -53,12 +55,13 @@ var configs = {
|
|
|
53
55
|
production: {
|
|
54
56
|
environment: "production",
|
|
55
57
|
serviceUrls: {
|
|
56
|
-
auth: "https://auth.
|
|
58
|
+
auth: "https://auth.shellapps.com",
|
|
57
59
|
apps: "https://apps.shellapps.com",
|
|
58
60
|
blog: "https://blog.shellapps.com",
|
|
59
61
|
engineering: "https://engineering.shellapps.com",
|
|
60
|
-
admin: "https://admin.shelllabs.net"
|
|
62
|
+
admin: "https://admin.shelllabs.net",
|
|
61
63
|
// ShellLabs admin
|
|
64
|
+
payments: "https://payments.shellapps.com"
|
|
62
65
|
},
|
|
63
66
|
s3: {
|
|
64
67
|
buckets: {
|
|
@@ -98,21 +101,95 @@ function getMongoConfig() {
|
|
|
98
101
|
function getFeatureFlags() {
|
|
99
102
|
return getConfig().featureFlags;
|
|
100
103
|
}
|
|
104
|
+
|
|
105
|
+
// src/core-nav.ts
|
|
106
|
+
var CORE_NAV_ENTRIES = [
|
|
107
|
+
{ key: "apps", name: "Apps", app: "apps", path: "/" },
|
|
108
|
+
{ key: "store", name: "Store", app: "apps", path: "/store" },
|
|
109
|
+
{ key: "profile", name: "Profile", app: "auth", path: "/profile" },
|
|
110
|
+
{ key: "profiles", name: "Profiles", app: "auth", path: "/profiles" },
|
|
111
|
+
{ key: "groups", name: "Groups", app: "auth", path: "/groups" },
|
|
112
|
+
{ key: "data", name: "Data", app: "auth", path: "/data" },
|
|
113
|
+
{ key: "network", name: "Network", app: "auth", path: "/network" },
|
|
114
|
+
{ key: "feedback", name: "Feedback", app: "auth", path: "/feedback" },
|
|
115
|
+
{ key: "privacy", name: "Privacy", app: "auth", path: "/settings/privacy" },
|
|
116
|
+
{ key: "security", name: "Security", app: "auth", path: "/settings/security" },
|
|
117
|
+
{ key: "permissions", name: "Permissions", app: "auth", path: "/settings/permissions" },
|
|
118
|
+
{ key: "appearance", name: "Appearance", app: "auth", path: "/settings/appearance" },
|
|
119
|
+
{ key: "builder-tools", name: "Builder Tools", app: "auth", path: "/settings/builder" },
|
|
120
|
+
{ key: "api-keys", name: "API Keys", app: "auth", path: "/settings/builder/keys" },
|
|
121
|
+
{ key: "subscriptions", name: "Subscriptions", app: "payments", path: "/subscriptions" },
|
|
122
|
+
{ key: "purchases", name: "Purchases", app: "payments", path: "/purchases" },
|
|
123
|
+
{ key: "invoices", name: "Invoices", app: "payments", path: "/invoices" },
|
|
124
|
+
{ key: "tokens", name: "Tokens", app: "payments", path: "/tokens" },
|
|
125
|
+
{ key: "usage", name: "Usage", app: "payments", path: "/usage" },
|
|
126
|
+
{ key: "payment-methods", name: "Payment Methods", app: "payments", path: "/payment-methods" },
|
|
127
|
+
{ key: "payment-settings", name: "Payment Settings", app: "payments", path: "/settings" }
|
|
128
|
+
];
|
|
129
|
+
function stripTrailingSlashes(origin) {
|
|
130
|
+
return origin.replace(/\/+$/, "");
|
|
131
|
+
}
|
|
132
|
+
function normalisePath(path) {
|
|
133
|
+
const trimmed = path.replace(/\/+$/, "");
|
|
134
|
+
return trimmed === "" ? "/" : trimmed;
|
|
135
|
+
}
|
|
136
|
+
var ORIGIN_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/[^/?#]*)(.*)$/i;
|
|
137
|
+
function splitHref(href) {
|
|
138
|
+
const match = ORIGIN_PATTERN.exec(href);
|
|
139
|
+
if (!match) {
|
|
140
|
+
return { origin: "", path: href.split(/[?#]/)[0] || "/" };
|
|
141
|
+
}
|
|
142
|
+
const rest = match[2];
|
|
143
|
+
const path = (rest ? rest.split(/[?#]/)[0] : "") || "/";
|
|
144
|
+
return { origin: match[1], path };
|
|
145
|
+
}
|
|
146
|
+
function getCoreNav() {
|
|
147
|
+
const serviceUrls = getServiceUrls();
|
|
148
|
+
return CORE_NAV_ENTRIES.map((entry) => ({
|
|
149
|
+
key: entry.key,
|
|
150
|
+
name: entry.name,
|
|
151
|
+
app: entry.app,
|
|
152
|
+
href: `${stripTrailingSlashes(serviceUrls[entry.app])}${entry.path}`
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
function isCurrentCoreLink(link, currentOrigin, currentPath) {
|
|
156
|
+
const { origin, path } = splitHref(link.href);
|
|
157
|
+
const linkOrigin = stripTrailingSlashes(origin).toLowerCase();
|
|
158
|
+
const otherOrigin = stripTrailingSlashes(currentOrigin).toLowerCase();
|
|
159
|
+
if (linkOrigin !== otherOrigin) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return normalisePath(path) === normalisePath(currentPath);
|
|
163
|
+
}
|
|
164
|
+
function markCurrentCoreNav(nav, currentOrigin, currentPath) {
|
|
165
|
+
return nav.map((link) => ({
|
|
166
|
+
...link,
|
|
167
|
+
current: isCurrentCoreLink(link, currentOrigin, currentPath)
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/index.ts
|
|
101
172
|
var index_default = {
|
|
102
173
|
getConfig,
|
|
103
174
|
getEnvironment,
|
|
104
175
|
getServiceUrls,
|
|
105
176
|
getS3Config,
|
|
106
177
|
getMongoConfig,
|
|
107
|
-
getFeatureFlags
|
|
178
|
+
getFeatureFlags,
|
|
179
|
+
getCoreNav,
|
|
180
|
+
isCurrentCoreLink,
|
|
181
|
+
markCurrentCoreNav
|
|
108
182
|
};
|
|
109
183
|
export {
|
|
110
184
|
index_default as default,
|
|
111
185
|
getConfig,
|
|
186
|
+
getCoreNav,
|
|
112
187
|
getEnvironment,
|
|
113
188
|
getFeatureFlags,
|
|
114
189
|
getMongoConfig,
|
|
115
190
|
getS3Config,
|
|
116
|
-
getServiceUrls
|
|
191
|
+
getServiceUrls,
|
|
192
|
+
isCurrentCoreLink,
|
|
193
|
+
markCurrentCoreNav
|
|
117
194
|
};
|
|
118
195
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type Environment = 'development' | 'staging' | 'production';\n\nexport interface ServiceUrls {\n auth: string;\n apps: string;\n blog: string;\n engineering: string;\n admin: string; // ShellLabs\n}\n\nexport interface S3Config {\n buckets: {\n assets: string;\n uploads: string;\n backups: string;\n };\n}\n\nexport interface MongoConfig {\n database: string;\n authDatabase?: string;\n}\n\nexport interface FeatureFlags {\n [key: string]: boolean;\n}\n\nexport interface Config {\n environment: Environment;\n serviceUrls: ServiceUrls;\n s3: S3Config;\n mongodb: MongoConfig;\n featureFlags: FeatureFlags;\n}\n\nconst configs: Record<Environment, Config> = {\n development: {\n environment: 'development',\n serviceUrls: {\n auth: 'http://localhost:3001',\n apps: 'http://localhost:3000',\n blog: 'http://localhost:3002',\n engineering: 'http://localhost:3003',\n admin: 'http://localhost:3004', // ShellLabs admin\n },\n s3: {\n buckets: {\n assets: 'shellapps-dev-assets',\n uploads: 'shellapps-dev-uploads',\n backups: 'shellapps-dev-backups',\n },\n },\n mongodb: {\n database: 'shellapps_dev',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n staging: {\n environment: 'staging',\n serviceUrls: {\n auth: 'https://auth.shelllabs.net',\n apps: 'https://apps.shellapps.net',\n blog: 'https://blog.shellapps.net',\n engineering: 'https://engineering.shellapps.net',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n },\n s3: {\n buckets: {\n assets: 'shellapps-staging-assets',\n uploads: 'shellapps-staging-uploads',\n backups: 'shellapps-staging-backups',\n },\n },\n mongodb: {\n database: 'shellapps_staging',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n production: {\n environment: 'production',\n serviceUrls: {\n auth: 'https://auth.shelllabs.net',\n apps: 'https://apps.shellapps.com',\n blog: 'https://blog.shellapps.com',\n engineering: 'https://engineering.shellapps.com',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n },\n s3: {\n buckets: {\n assets: 'shellapps-prod-assets',\n uploads: 'shellapps-prod-uploads',\n backups: 'shellapps-prod-backups',\n },\n },\n mongodb: {\n database: 'shellapps_production',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n};\n\nexport function getConfig(): Config {\n const env = (process.env.SHELLAPPS_ENV || 'development') as Environment;\n \n if (!configs[env]) {\n throw new Error(`Invalid environment: ${env}. Must be one of: development, staging, production`);\n }\n \n return configs[env];\n}\n\n// Export individual getters for convenience\nexport function getEnvironment(): Environment {\n return getConfig().environment;\n}\n\nexport function getServiceUrls(): ServiceUrls {\n return getConfig().serviceUrls;\n}\n\nexport function getS3Config(): S3Config {\n return getConfig().s3;\n}\n\nexport function getMongoConfig(): MongoConfig {\n return getConfig().mongodb;\n}\n\nexport function getFeatureFlags(): FeatureFlags {\n return getConfig().featureFlags;\n}\n\n// Default export\nexport default {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n};"],"mappings":";AAmCA,IAAM,UAAuC;AAAA,EAC3C,aAAa;AAAA,IACX,aAAa;AAAA,IACb,aAAa;AAAA,MACX,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,MACb,OAAO;AAAA;AAAA,IACT;AAAA,IACA,IAAI;AAAA,MACF,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,UAAU;AAAA,MACV,cAAc;AAAA,IAChB;AAAA,IACA,cAAc;AAAA;AAAA,IAEd;AAAA,EACF;AAAA,EACA,SAAS;AAAA,IACP,aAAa;AAAA,IACb,aAAa;AAAA,MACX,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,MACb,OAAO;AAAA;AAAA,IACT;AAAA,IACA,IAAI;AAAA,MACF,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,UAAU;AAAA,MACV,cAAc;AAAA,IAChB;AAAA,IACA,cAAc;AAAA;AAAA,IAEd;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,aAAa;AAAA,IACb,aAAa;AAAA,MACX,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,MACb,OAAO;AAAA;AAAA,IACT;AAAA,IACA,IAAI;AAAA,MACF,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,UAAU;AAAA,MACV,cAAc;AAAA,IAChB;AAAA,IACA,cAAc;AAAA;AAAA,IAEd;AAAA,EACF;AACF;AAEO,SAAS,YAAoB;AAClC,QAAM,MAAO,QAAQ,IAAI,iBAAiB;AAE1C,MAAI,CAAC,QAAQ,GAAG,GAAG;AACjB,UAAM,IAAI,MAAM,wBAAwB,GAAG,oDAAoD;AAAA,EACjG;AAEA,SAAO,QAAQ,GAAG;AACpB;AAGO,SAAS,iBAA8B;AAC5C,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,iBAA8B;AAC5C,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,cAAwB;AACtC,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,iBAA8B;AAC5C,SAAO,UAAU,EAAE;AACrB;AAEO,SAAS,kBAAgC;AAC9C,SAAO,UAAU,EAAE;AACrB;AAGA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/core-nav.ts","../src/index.ts"],"sourcesContent":["export type Environment = 'development' | 'staging' | 'production';\n\nexport interface ServiceUrls {\n auth: string;\n apps: string;\n blog: string;\n engineering: string;\n admin: string; // ShellLabs\n payments: string;\n}\n\nexport interface S3Config {\n buckets: {\n assets: string;\n uploads: string;\n backups: string;\n };\n}\n\nexport interface MongoConfig {\n database: string;\n authDatabase?: string;\n}\n\nexport interface FeatureFlags {\n [key: string]: boolean;\n}\n\nexport interface Config {\n environment: Environment;\n serviceUrls: ServiceUrls;\n s3: S3Config;\n mongodb: MongoConfig;\n featureFlags: FeatureFlags;\n}\n\nconst configs: Record<Environment, Config> = {\n development: {\n environment: 'development',\n serviceUrls: {\n auth: 'http://localhost:3001',\n apps: 'http://localhost:3000',\n blog: 'http://localhost:3002',\n engineering: 'http://localhost:3003',\n admin: 'http://localhost:3004', // ShellLabs admin\n payments: 'http://localhost:3003',\n },\n s3: {\n buckets: {\n assets: 'shellapps-dev-assets',\n uploads: 'shellapps-dev-uploads',\n backups: 'shellapps-dev-backups',\n },\n },\n mongodb: {\n database: 'shellapps_dev',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n staging: {\n environment: 'staging',\n serviceUrls: {\n auth: 'https://auth.shellapps.net',\n apps: 'https://apps.shellapps.net',\n blog: 'https://blog.shellapps.net',\n engineering: 'https://engineering.shellapps.net',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n payments: 'https://payments.shellapps.net',\n },\n s3: {\n buckets: {\n assets: 'shellapps-staging-assets',\n uploads: 'shellapps-staging-uploads',\n backups: 'shellapps-staging-backups',\n },\n },\n mongodb: {\n database: 'shellapps_staging',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n production: {\n environment: 'production',\n serviceUrls: {\n auth: 'https://auth.shellapps.com',\n apps: 'https://apps.shellapps.com',\n blog: 'https://blog.shellapps.com',\n engineering: 'https://engineering.shellapps.com',\n admin: 'https://admin.shelllabs.net', // ShellLabs admin\n payments: 'https://payments.shellapps.com',\n },\n s3: {\n buckets: {\n assets: 'shellapps-prod-assets',\n uploads: 'shellapps-prod-uploads',\n backups: 'shellapps-prod-backups',\n },\n },\n mongodb: {\n database: 'shellapps_production',\n authDatabase: 'admin',\n },\n featureFlags: {\n // Add feature flags as needed\n },\n },\n};\n\nexport function getConfig(): Config {\n const env = (process.env.SHELLAPPS_ENV || 'development') as Environment;\n \n if (!configs[env]) {\n throw new Error(`Invalid environment: ${env}. Must be one of: development, staging, production`);\n }\n \n return configs[env];\n}\n\n// Export individual getters for convenience\nexport function getEnvironment(): Environment {\n return getConfig().environment;\n}\n\nexport function getServiceUrls(): ServiceUrls {\n return getConfig().serviceUrls;\n}\n\nexport function getS3Config(): S3Config {\n return getConfig().s3;\n}\n\nexport function getMongoConfig(): MongoConfig {\n return getConfig().mongodb;\n}\n\nexport function getFeatureFlags(): FeatureFlags {\n return getConfig().featureFlags;\n}\n","import { getServiceUrls } from './config';\n\n/**\n * The three core ShellApps apps that own a slice of the shared core nav.\n * Each maps to a key on {@link ServiceUrls}, so a link's origin is resolved\n * per environment (development / staging / production).\n */\nexport type CoreNavApp = 'apps' | 'auth' | 'payments';\n\n/**\n * One entry in the shared core nav. `href` is always absolute — the owning\n * app's origin for the current environment, plus the entry's path.\n */\nexport interface CoreNavLink {\n key: string;\n name: string;\n href: string;\n app: CoreNavApp;\n}\n\n/** A {@link CoreNavLink} annotated with whether it is the current location. */\nexport type CoreNavLinkWithCurrent = CoreNavLink & { current: boolean };\n\ninterface CoreNavEntry {\n key: string;\n name: string;\n app: CoreNavApp;\n path: string;\n}\n\n/**\n * The flat core nav, in render order. Shared verbatim by apps.shellapps.com,\n * auth.shellapps.com and payments.shellapps.com — each renders the same list,\n * so ordering here is the ordering everywhere.\n */\nconst CORE_NAV_ENTRIES: readonly CoreNavEntry[] = [\n { key: 'apps', name: 'Apps', app: 'apps', path: '/' },\n { key: 'store', name: 'Store', app: 'apps', path: '/store' },\n { key: 'profile', name: 'Profile', app: 'auth', path: '/profile' },\n { key: 'profiles', name: 'Profiles', app: 'auth', path: '/profiles' },\n { key: 'groups', name: 'Groups', app: 'auth', path: '/groups' },\n { key: 'data', name: 'Data', app: 'auth', path: '/data' },\n { key: 'network', name: 'Network', app: 'auth', path: '/network' },\n { key: 'feedback', name: 'Feedback', app: 'auth', path: '/feedback' },\n { key: 'privacy', name: 'Privacy', app: 'auth', path: '/settings/privacy' },\n { key: 'security', name: 'Security', app: 'auth', path: '/settings/security' },\n { key: 'permissions', name: 'Permissions', app: 'auth', path: '/settings/permissions' },\n { key: 'appearance', name: 'Appearance', app: 'auth', path: '/settings/appearance' },\n { key: 'builder-tools', name: 'Builder Tools', app: 'auth', path: '/settings/builder' },\n { key: 'api-keys', name: 'API Keys', app: 'auth', path: '/settings/builder/keys' },\n { key: 'subscriptions', name: 'Subscriptions', app: 'payments', path: '/subscriptions' },\n { key: 'purchases', name: 'Purchases', app: 'payments', path: '/purchases' },\n { key: 'invoices', name: 'Invoices', app: 'payments', path: '/invoices' },\n { key: 'tokens', name: 'Tokens', app: 'payments', path: '/tokens' },\n { key: 'usage', name: 'Usage', app: 'payments', path: '/usage' },\n { key: 'payment-methods', name: 'Payment Methods', app: 'payments', path: '/payment-methods' },\n { key: 'payment-settings', name: 'Payment Settings', app: 'payments', path: '/settings' },\n];\n\n/** Strip any trailing slashes so an origin never double-slashes into a path. */\nfunction stripTrailingSlashes(origin: string): string {\n return origin.replace(/\\/+$/, '');\n}\n\n/**\n * Normalise a path for comparison: a trailing slash is insignificant\n * (`/store/` === `/store`), except at the root, which stays `/`.\n */\nfunction normalisePath(path: string): string {\n const trimmed = path.replace(/\\/+$/, '');\n return trimmed === '' ? '/' : trimmed;\n}\n\nconst ORIGIN_PATTERN = /^([a-z][a-z0-9+.-]*:\\/\\/[^/?#]*)(.*)$/i;\n\n/** Split an absolute href into its origin and path, framework-free. */\nfunction splitHref(href: string): { origin: string; path: string } {\n const match = ORIGIN_PATTERN.exec(href);\n if (!match) {\n return { origin: '', path: href.split(/[?#]/)[0] || '/' };\n }\n const rest = match[2];\n const path = (rest ? rest.split(/[?#]/)[0] : '') || '/';\n return { origin: match[1], path };\n}\n\n/**\n * The shared core nav for the current environment: a flat list of absolute\n * links, in render order.\n */\nexport function getCoreNav(): CoreNavLink[] {\n const serviceUrls = getServiceUrls();\n\n return CORE_NAV_ENTRIES.map((entry) => ({\n key: entry.key,\n name: entry.name,\n app: entry.app,\n href: `${stripTrailingSlashes(serviceUrls[entry.app])}${entry.path}`,\n }));\n}\n\n/**\n * Whether `link` points at the location described by `currentOrigin` /\n * `currentPath`. Origins compare case-insensitively and ignore trailing\n * slashes; paths compare with a trailing slash treated as insignificant.\n */\nexport function isCurrentCoreLink(\n link: CoreNavLink,\n currentOrigin: string,\n currentPath: string\n): boolean {\n const { origin, path } = splitHref(link.href);\n\n const linkOrigin = stripTrailingSlashes(origin).toLowerCase();\n const otherOrigin = stripTrailingSlashes(currentOrigin).toLowerCase();\n if (linkOrigin !== otherOrigin) {\n return false;\n }\n\n return normalisePath(path) === normalisePath(currentPath);\n}\n\n/**\n * Annotate every link with whether it is the current one. Pure — the input\n * array and its links are never mutated.\n */\nexport function markCurrentCoreNav(\n nav: CoreNavLink[],\n currentOrigin: string,\n currentPath: string\n): CoreNavLinkWithCurrent[] {\n return nav.map((link) => ({\n ...link,\n current: isCurrentCoreLink(link, currentOrigin, currentPath),\n }));\n}\n","export type {\n Environment,\n ServiceUrls,\n S3Config,\n MongoConfig,\n FeatureFlags,\n Config,\n} from './config';\n\nexport {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n} from './config';\n\nexport type { CoreNavApp, CoreNavLink, CoreNavLinkWithCurrent } from './core-nav';\n\nexport { getCoreNav, isCurrentCoreLink, markCurrentCoreNav } from './core-nav';\n\nimport {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n} from './config';\nimport { getCoreNav, isCurrentCoreLink, markCurrentCoreNav } from './core-nav';\n\n// Default export\nexport default {\n getConfig,\n getEnvironment,\n getServiceUrls,\n getS3Config,\n getMongoConfig,\n getFeatureFlags,\n getCoreNav,\n isCurrentCoreLink,\n markCurrentCoreNav,\n};\n"],"mappings":";AAoCA,IAAM,UAAuC;AAAA,EAC3C,aAAa;AAAA,IACX,aAAa;AAAA,I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A,IACX,MAAM,MAAM;AAAA,IACZ,KAAK,MAAM;AAAA,IACX,MAAM,GAAG,qBAAqB,YAAY,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,IAAI;AAAA,EACpE,EAAE;AACJ;AAOO,SAAS,kBACd,MACA,eACA,aACS;AACT,QAAM,EAAE,QAAQ,KAAK,IAAI,UAAU,KAAK,IAAI;AAE5C,QAAM,aAAa,qBAAqB,MAAM,EAAE,YAAY;AAC5D,QAAM,cAAc,qBAAqB,aAAa,EAAE,YAAY;AACpE,MAAI,eAAe,aAAa;AAC9B,WAAO;AAAA,EACT;AAEA,SAAO,cAAc,IAAI,MAAM,cAAc,WAAW;AAC1D;AAMO,SAAS,mBACd,KACA,eACA,aAC0B;AAC1B,SAAO,IAAI,IAAI,CAAC,UAAU;AAAA,IACxB,GAAG;AAAA,IACH,SAAS,kBAAkB,MAAM,eAAe,WAAW;AAAA,EAC7D,EAAE;AACJ;;;ACtGA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellapps/config",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Configuration management for ShellApps ecosystem",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,12 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"src"
|
|
17
|
+
"src",
|
|
18
|
+
"!src/**/*.test.ts"
|
|
18
19
|
],
|
|
19
20
|
"scripts": {
|
|
20
21
|
"build": "tsup",
|
|
21
22
|
"dev": "tsup --watch",
|
|
22
|
-
"clean": "rm -rf dist"
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"test": "vitest run"
|
|
23
25
|
},
|
|
24
26
|
"keywords": [
|
|
25
27
|
"config",
|
|
@@ -31,7 +33,8 @@
|
|
|
31
33
|
"license": "MIT",
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"tsup": "^8.0.1",
|
|
34
|
-
"typescript": "^5.3.3"
|
|
36
|
+
"typescript": "^5.3.3",
|
|
37
|
+
"vitest": "^1.6.1"
|
|
35
38
|
},
|
|
36
39
|
"repository": {
|
|
37
40
|
"type": "git",
|
|
@@ -42,5 +45,5 @@
|
|
|
42
45
|
"bugs": {
|
|
43
46
|
"url": "https://github.com/ShellTechnology/shellapps-js/issues"
|
|
44
47
|
},
|
|
45
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "119627aaed4fe27271ad05518952df4b2fc676c1"
|
|
46
49
|
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export type Environment = 'development' | 'staging' | 'production';
|
|
2
|
+
|
|
3
|
+
export interface ServiceUrls {
|
|
4
|
+
auth: string;
|
|
5
|
+
apps: string;
|
|
6
|
+
blog: string;
|
|
7
|
+
engineering: string;
|
|
8
|
+
admin: string; // ShellLabs
|
|
9
|
+
payments: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface S3Config {
|
|
13
|
+
buckets: {
|
|
14
|
+
assets: string;
|
|
15
|
+
uploads: string;
|
|
16
|
+
backups: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MongoConfig {
|
|
21
|
+
database: string;
|
|
22
|
+
authDatabase?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface FeatureFlags {
|
|
26
|
+
[key: string]: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Config {
|
|
30
|
+
environment: Environment;
|
|
31
|
+
serviceUrls: ServiceUrls;
|
|
32
|
+
s3: S3Config;
|
|
33
|
+
mongodb: MongoConfig;
|
|
34
|
+
featureFlags: FeatureFlags;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const configs: Record<Environment, Config> = {
|
|
38
|
+
development: {
|
|
39
|
+
environment: 'development',
|
|
40
|
+
serviceUrls: {
|
|
41
|
+
auth: 'http://localhost:3001',
|
|
42
|
+
apps: 'http://localhost:3000',
|
|
43
|
+
blog: 'http://localhost:3002',
|
|
44
|
+
engineering: 'http://localhost:3003',
|
|
45
|
+
admin: 'http://localhost:3004', // ShellLabs admin
|
|
46
|
+
payments: 'http://localhost:3003',
|
|
47
|
+
},
|
|
48
|
+
s3: {
|
|
49
|
+
buckets: {
|
|
50
|
+
assets: 'shellapps-dev-assets',
|
|
51
|
+
uploads: 'shellapps-dev-uploads',
|
|
52
|
+
backups: 'shellapps-dev-backups',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
mongodb: {
|
|
56
|
+
database: 'shellapps_dev',
|
|
57
|
+
authDatabase: 'admin',
|
|
58
|
+
},
|
|
59
|
+
featureFlags: {
|
|
60
|
+
// Add feature flags as needed
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
staging: {
|
|
64
|
+
environment: 'staging',
|
|
65
|
+
serviceUrls: {
|
|
66
|
+
auth: 'https://auth.shellapps.net',
|
|
67
|
+
apps: 'https://apps.shellapps.net',
|
|
68
|
+
blog: 'https://blog.shellapps.net',
|
|
69
|
+
engineering: 'https://engineering.shellapps.net',
|
|
70
|
+
admin: 'https://admin.shelllabs.net', // ShellLabs admin
|
|
71
|
+
payments: 'https://payments.shellapps.net',
|
|
72
|
+
},
|
|
73
|
+
s3: {
|
|
74
|
+
buckets: {
|
|
75
|
+
assets: 'shellapps-staging-assets',
|
|
76
|
+
uploads: 'shellapps-staging-uploads',
|
|
77
|
+
backups: 'shellapps-staging-backups',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
mongodb: {
|
|
81
|
+
database: 'shellapps_staging',
|
|
82
|
+
authDatabase: 'admin',
|
|
83
|
+
},
|
|
84
|
+
featureFlags: {
|
|
85
|
+
// Add feature flags as needed
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
production: {
|
|
89
|
+
environment: 'production',
|
|
90
|
+
serviceUrls: {
|
|
91
|
+
auth: 'https://auth.shellapps.com',
|
|
92
|
+
apps: 'https://apps.shellapps.com',
|
|
93
|
+
blog: 'https://blog.shellapps.com',
|
|
94
|
+
engineering: 'https://engineering.shellapps.com',
|
|
95
|
+
admin: 'https://admin.shelllabs.net', // ShellLabs admin
|
|
96
|
+
payments: 'https://payments.shellapps.com',
|
|
97
|
+
},
|
|
98
|
+
s3: {
|
|
99
|
+
buckets: {
|
|
100
|
+
assets: 'shellapps-prod-assets',
|
|
101
|
+
uploads: 'shellapps-prod-uploads',
|
|
102
|
+
backups: 'shellapps-prod-backups',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
mongodb: {
|
|
106
|
+
database: 'shellapps_production',
|
|
107
|
+
authDatabase: 'admin',
|
|
108
|
+
},
|
|
109
|
+
featureFlags: {
|
|
110
|
+
// Add feature flags as needed
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export function getConfig(): Config {
|
|
116
|
+
const env = (process.env.SHELLAPPS_ENV || 'development') as Environment;
|
|
117
|
+
|
|
118
|
+
if (!configs[env]) {
|
|
119
|
+
throw new Error(`Invalid environment: ${env}. Must be one of: development, staging, production`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return configs[env];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Export individual getters for convenience
|
|
126
|
+
export function getEnvironment(): Environment {
|
|
127
|
+
return getConfig().environment;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function getServiceUrls(): ServiceUrls {
|
|
131
|
+
return getConfig().serviceUrls;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function getS3Config(): S3Config {
|
|
135
|
+
return getConfig().s3;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getMongoConfig(): MongoConfig {
|
|
139
|
+
return getConfig().mongodb;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function getFeatureFlags(): FeatureFlags {
|
|
143
|
+
return getConfig().featureFlags;
|
|
144
|
+
}
|
package/src/core-nav.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { getServiceUrls } from './config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The three core ShellApps apps that own a slice of the shared core nav.
|
|
5
|
+
* Each maps to a key on {@link ServiceUrls}, so a link's origin is resolved
|
|
6
|
+
* per environment (development / staging / production).
|
|
7
|
+
*/
|
|
8
|
+
export type CoreNavApp = 'apps' | 'auth' | 'payments';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* One entry in the shared core nav. `href` is always absolute — the owning
|
|
12
|
+
* app's origin for the current environment, plus the entry's path.
|
|
13
|
+
*/
|
|
14
|
+
export interface CoreNavLink {
|
|
15
|
+
key: string;
|
|
16
|
+
name: string;
|
|
17
|
+
href: string;
|
|
18
|
+
app: CoreNavApp;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A {@link CoreNavLink} annotated with whether it is the current location. */
|
|
22
|
+
export type CoreNavLinkWithCurrent = CoreNavLink & { current: boolean };
|
|
23
|
+
|
|
24
|
+
interface CoreNavEntry {
|
|
25
|
+
key: string;
|
|
26
|
+
name: string;
|
|
27
|
+
app: CoreNavApp;
|
|
28
|
+
path: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The flat core nav, in render order. Shared verbatim by apps.shellapps.com,
|
|
33
|
+
* auth.shellapps.com and payments.shellapps.com — each renders the same list,
|
|
34
|
+
* so ordering here is the ordering everywhere.
|
|
35
|
+
*/
|
|
36
|
+
const CORE_NAV_ENTRIES: readonly CoreNavEntry[] = [
|
|
37
|
+
{ key: 'apps', name: 'Apps', app: 'apps', path: '/' },
|
|
38
|
+
{ key: 'store', name: 'Store', app: 'apps', path: '/store' },
|
|
39
|
+
{ key: 'profile', name: 'Profile', app: 'auth', path: '/profile' },
|
|
40
|
+
{ key: 'profiles', name: 'Profiles', app: 'auth', path: '/profiles' },
|
|
41
|
+
{ key: 'groups', name: 'Groups', app: 'auth', path: '/groups' },
|
|
42
|
+
{ key: 'data', name: 'Data', app: 'auth', path: '/data' },
|
|
43
|
+
{ key: 'network', name: 'Network', app: 'auth', path: '/network' },
|
|
44
|
+
{ key: 'feedback', name: 'Feedback', app: 'auth', path: '/feedback' },
|
|
45
|
+
{ key: 'privacy', name: 'Privacy', app: 'auth', path: '/settings/privacy' },
|
|
46
|
+
{ key: 'security', name: 'Security', app: 'auth', path: '/settings/security' },
|
|
47
|
+
{ key: 'permissions', name: 'Permissions', app: 'auth', path: '/settings/permissions' },
|
|
48
|
+
{ key: 'appearance', name: 'Appearance', app: 'auth', path: '/settings/appearance' },
|
|
49
|
+
{ key: 'builder-tools', name: 'Builder Tools', app: 'auth', path: '/settings/builder' },
|
|
50
|
+
{ key: 'api-keys', name: 'API Keys', app: 'auth', path: '/settings/builder/keys' },
|
|
51
|
+
{ key: 'subscriptions', name: 'Subscriptions', app: 'payments', path: '/subscriptions' },
|
|
52
|
+
{ key: 'purchases', name: 'Purchases', app: 'payments', path: '/purchases' },
|
|
53
|
+
{ key: 'invoices', name: 'Invoices', app: 'payments', path: '/invoices' },
|
|
54
|
+
{ key: 'tokens', name: 'Tokens', app: 'payments', path: '/tokens' },
|
|
55
|
+
{ key: 'usage', name: 'Usage', app: 'payments', path: '/usage' },
|
|
56
|
+
{ key: 'payment-methods', name: 'Payment Methods', app: 'payments', path: '/payment-methods' },
|
|
57
|
+
{ key: 'payment-settings', name: 'Payment Settings', app: 'payments', path: '/settings' },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
/** Strip any trailing slashes so an origin never double-slashes into a path. */
|
|
61
|
+
function stripTrailingSlashes(origin: string): string {
|
|
62
|
+
return origin.replace(/\/+$/, '');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Normalise a path for comparison: a trailing slash is insignificant
|
|
67
|
+
* (`/store/` === `/store`), except at the root, which stays `/`.
|
|
68
|
+
*/
|
|
69
|
+
function normalisePath(path: string): string {
|
|
70
|
+
const trimmed = path.replace(/\/+$/, '');
|
|
71
|
+
return trimmed === '' ? '/' : trimmed;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ORIGIN_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/[^/?#]*)(.*)$/i;
|
|
75
|
+
|
|
76
|
+
/** Split an absolute href into its origin and path, framework-free. */
|
|
77
|
+
function splitHref(href: string): { origin: string; path: string } {
|
|
78
|
+
const match = ORIGIN_PATTERN.exec(href);
|
|
79
|
+
if (!match) {
|
|
80
|
+
return { origin: '', path: href.split(/[?#]/)[0] || '/' };
|
|
81
|
+
}
|
|
82
|
+
const rest = match[2];
|
|
83
|
+
const path = (rest ? rest.split(/[?#]/)[0] : '') || '/';
|
|
84
|
+
return { origin: match[1], path };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The shared core nav for the current environment: a flat list of absolute
|
|
89
|
+
* links, in render order.
|
|
90
|
+
*/
|
|
91
|
+
export function getCoreNav(): CoreNavLink[] {
|
|
92
|
+
const serviceUrls = getServiceUrls();
|
|
93
|
+
|
|
94
|
+
return CORE_NAV_ENTRIES.map((entry) => ({
|
|
95
|
+
key: entry.key,
|
|
96
|
+
name: entry.name,
|
|
97
|
+
app: entry.app,
|
|
98
|
+
href: `${stripTrailingSlashes(serviceUrls[entry.app])}${entry.path}`,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Whether `link` points at the location described by `currentOrigin` /
|
|
104
|
+
* `currentPath`. Origins compare case-insensitively and ignore trailing
|
|
105
|
+
* slashes; paths compare with a trailing slash treated as insignificant.
|
|
106
|
+
*/
|
|
107
|
+
export function isCurrentCoreLink(
|
|
108
|
+
link: CoreNavLink,
|
|
109
|
+
currentOrigin: string,
|
|
110
|
+
currentPath: string
|
|
111
|
+
): boolean {
|
|
112
|
+
const { origin, path } = splitHref(link.href);
|
|
113
|
+
|
|
114
|
+
const linkOrigin = stripTrailingSlashes(origin).toLowerCase();
|
|
115
|
+
const otherOrigin = stripTrailingSlashes(currentOrigin).toLowerCase();
|
|
116
|
+
if (linkOrigin !== otherOrigin) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return normalisePath(path) === normalisePath(currentPath);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Annotate every link with whether it is the current one. Pure — the input
|
|
125
|
+
* array and its links are never mutated.
|
|
126
|
+
*/
|
|
127
|
+
export function markCurrentCoreNav(
|
|
128
|
+
nav: CoreNavLink[],
|
|
129
|
+
currentOrigin: string,
|
|
130
|
+
currentPath: string
|
|
131
|
+
): CoreNavLinkWithCurrent[] {
|
|
132
|
+
return nav.map((link) => ({
|
|
133
|
+
...link,
|
|
134
|
+
current: isCurrentCoreLink(link, currentOrigin, currentPath),
|
|
135
|
+
}));
|
|
136
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,143 +1,34 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface MongoConfig {
|
|
20
|
-
database: string;
|
|
21
|
-
authDatabase?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface FeatureFlags {
|
|
25
|
-
[key: string]: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface Config {
|
|
29
|
-
environment: Environment;
|
|
30
|
-
serviceUrls: ServiceUrls;
|
|
31
|
-
s3: S3Config;
|
|
32
|
-
mongodb: MongoConfig;
|
|
33
|
-
featureFlags: FeatureFlags;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const configs: Record<Environment, Config> = {
|
|
37
|
-
development: {
|
|
38
|
-
environment: 'development',
|
|
39
|
-
serviceUrls: {
|
|
40
|
-
auth: 'http://localhost:3001',
|
|
41
|
-
apps: 'http://localhost:3000',
|
|
42
|
-
blog: 'http://localhost:3002',
|
|
43
|
-
engineering: 'http://localhost:3003',
|
|
44
|
-
admin: 'http://localhost:3004', // ShellLabs admin
|
|
45
|
-
},
|
|
46
|
-
s3: {
|
|
47
|
-
buckets: {
|
|
48
|
-
assets: 'shellapps-dev-assets',
|
|
49
|
-
uploads: 'shellapps-dev-uploads',
|
|
50
|
-
backups: 'shellapps-dev-backups',
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
mongodb: {
|
|
54
|
-
database: 'shellapps_dev',
|
|
55
|
-
authDatabase: 'admin',
|
|
56
|
-
},
|
|
57
|
-
featureFlags: {
|
|
58
|
-
// Add feature flags as needed
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
staging: {
|
|
62
|
-
environment: 'staging',
|
|
63
|
-
serviceUrls: {
|
|
64
|
-
auth: 'https://auth.shelllabs.net',
|
|
65
|
-
apps: 'https://apps.shellapps.net',
|
|
66
|
-
blog: 'https://blog.shellapps.net',
|
|
67
|
-
engineering: 'https://engineering.shellapps.net',
|
|
68
|
-
admin: 'https://admin.shelllabs.net', // ShellLabs admin
|
|
69
|
-
},
|
|
70
|
-
s3: {
|
|
71
|
-
buckets: {
|
|
72
|
-
assets: 'shellapps-staging-assets',
|
|
73
|
-
uploads: 'shellapps-staging-uploads',
|
|
74
|
-
backups: 'shellapps-staging-backups',
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
mongodb: {
|
|
78
|
-
database: 'shellapps_staging',
|
|
79
|
-
authDatabase: 'admin',
|
|
80
|
-
},
|
|
81
|
-
featureFlags: {
|
|
82
|
-
// Add feature flags as needed
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
production: {
|
|
86
|
-
environment: 'production',
|
|
87
|
-
serviceUrls: {
|
|
88
|
-
auth: 'https://auth.shelllabs.net',
|
|
89
|
-
apps: 'https://apps.shellapps.com',
|
|
90
|
-
blog: 'https://blog.shellapps.com',
|
|
91
|
-
engineering: 'https://engineering.shellapps.com',
|
|
92
|
-
admin: 'https://admin.shelllabs.net', // ShellLabs admin
|
|
93
|
-
},
|
|
94
|
-
s3: {
|
|
95
|
-
buckets: {
|
|
96
|
-
assets: 'shellapps-prod-assets',
|
|
97
|
-
uploads: 'shellapps-prod-uploads',
|
|
98
|
-
backups: 'shellapps-prod-backups',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
mongodb: {
|
|
102
|
-
database: 'shellapps_production',
|
|
103
|
-
authDatabase: 'admin',
|
|
104
|
-
},
|
|
105
|
-
featureFlags: {
|
|
106
|
-
// Add feature flags as needed
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export function getConfig(): Config {
|
|
112
|
-
const env = (process.env.SHELLAPPS_ENV || 'development') as Environment;
|
|
113
|
-
|
|
114
|
-
if (!configs[env]) {
|
|
115
|
-
throw new Error(`Invalid environment: ${env}. Must be one of: development, staging, production`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return configs[env];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Export individual getters for convenience
|
|
122
|
-
export function getEnvironment(): Environment {
|
|
123
|
-
return getConfig().environment;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function getServiceUrls(): ServiceUrls {
|
|
127
|
-
return getConfig().serviceUrls;
|
|
128
|
-
}
|
|
1
|
+
export type {
|
|
2
|
+
Environment,
|
|
3
|
+
ServiceUrls,
|
|
4
|
+
S3Config,
|
|
5
|
+
MongoConfig,
|
|
6
|
+
FeatureFlags,
|
|
7
|
+
Config,
|
|
8
|
+
} from './config';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
getConfig,
|
|
12
|
+
getEnvironment,
|
|
13
|
+
getServiceUrls,
|
|
14
|
+
getS3Config,
|
|
15
|
+
getMongoConfig,
|
|
16
|
+
getFeatureFlags,
|
|
17
|
+
} from './config';
|
|
129
18
|
|
|
130
|
-
export
|
|
131
|
-
return getConfig().s3;
|
|
132
|
-
}
|
|
19
|
+
export type { CoreNavApp, CoreNavLink, CoreNavLinkWithCurrent } from './core-nav';
|
|
133
20
|
|
|
134
|
-
export
|
|
135
|
-
return getConfig().mongodb;
|
|
136
|
-
}
|
|
21
|
+
export { getCoreNav, isCurrentCoreLink, markCurrentCoreNav } from './core-nav';
|
|
137
22
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
23
|
+
import {
|
|
24
|
+
getConfig,
|
|
25
|
+
getEnvironment,
|
|
26
|
+
getServiceUrls,
|
|
27
|
+
getS3Config,
|
|
28
|
+
getMongoConfig,
|
|
29
|
+
getFeatureFlags,
|
|
30
|
+
} from './config';
|
|
31
|
+
import { getCoreNav, isCurrentCoreLink, markCurrentCoreNav } from './core-nav';
|
|
141
32
|
|
|
142
33
|
// Default export
|
|
143
34
|
export default {
|
|
@@ -147,4 +38,7 @@ export default {
|
|
|
147
38
|
getS3Config,
|
|
148
39
|
getMongoConfig,
|
|
149
40
|
getFeatureFlags,
|
|
150
|
-
|
|
41
|
+
getCoreNav,
|
|
42
|
+
isCurrentCoreLink,
|
|
43
|
+
markCurrentCoreNav,
|
|
44
|
+
};
|