@camox/api-contract 0.48.0 → 0.51.0
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/dist/drafts.js +1 -0
- package/dist/index.d.ts +1 -12745
- package/dist/locales.d.ts +25 -0
- package/dist/locales.js +29 -0
- package/dist/projects.d.ts +2 -0
- package/dist/projects.js +3 -1
- package/dist/router.d.ts +13208 -0
- package/dist/router.js +0 -0
- package/package.json +9 -1
- package/src/drafts.ts +2 -1
- package/src/index.ts +0 -3
- package/src/locales.ts +34 -0
- package/src/projects.ts +3 -0
- package/src/router.ts +5 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/locales.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The URL names the locale (ADR 0015): a non-default locale's paths sit under its prefix
|
|
4
|
+
* (`/de/preise`), the default locale's have none. Pure, so the API, the runtime and the browser
|
|
5
|
+
* read a path the same way.
|
|
6
|
+
*/
|
|
7
|
+
/** A locale of a project, as `locales.list` returns it. */
|
|
8
|
+
export type LocaleView = {
|
|
9
|
+
tag: string;
|
|
10
|
+
isDefault: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** A runtime path split into the locale it names and the locale-relative path after its prefix. */
|
|
13
|
+
export type LocalePath = {
|
|
14
|
+
locale: LocaleView;
|
|
15
|
+
path: string;
|
|
16
|
+
};
|
|
17
|
+
/** A locale's URL prefix: its tag in lowercase. The default locale has none. */
|
|
18
|
+
export declare function localePrefix(locale: LocaleView): string;
|
|
19
|
+
/**
|
|
20
|
+
* The locale a runtime path names, and the path after its prefix, without search or hash. A first
|
|
21
|
+
* segment that isn't a non-default locale's prefix leaves the path the default locale's. A
|
|
22
|
+
* locale's home is `/de`; `/de/` names it too.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseLocalePath(pathname: string, locales: readonly LocaleView[]): LocalePath;
|
|
25
|
+
//#endregion
|
package/dist/locales.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/locales.ts
|
|
2
|
+
/** A locale's URL prefix: its tag in lowercase. The default locale has none. */
|
|
3
|
+
function localePrefix(locale) {
|
|
4
|
+
return locale.isDefault ? "" : `/${locale.tag.toLowerCase()}`;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The locale a runtime path names, and the path after its prefix, without search or hash. A first
|
|
8
|
+
* segment that isn't a non-default locale's prefix leaves the path the default locale's. A
|
|
9
|
+
* locale's home is `/de`; `/de/` names it too.
|
|
10
|
+
*/
|
|
11
|
+
function parseLocalePath(pathname, locales) {
|
|
12
|
+
const path = pathname.replace(/[?#].*$/s, "") || "/";
|
|
13
|
+
const end = path.indexOf("/", 1);
|
|
14
|
+
const segment = end === -1 ? path.slice(1) : path.slice(1, end);
|
|
15
|
+
const named = locales.find((locale) => !locale.isDefault && localePrefix(locale) === `/${segment}`);
|
|
16
|
+
if (named) return {
|
|
17
|
+
locale: named,
|
|
18
|
+
path: end === -1 ? "/" : path.slice(end)
|
|
19
|
+
};
|
|
20
|
+
const fallback = locales.find((locale) => locale.isDefault);
|
|
21
|
+
if (!fallback) throw new Error("A project's locales include its default locale.");
|
|
22
|
+
return {
|
|
23
|
+
locale: fallback,
|
|
24
|
+
path
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { localePrefix, parseLocalePath };
|
package/dist/projects.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export declare const RESERVED_PROJECT_SLUGS: ReadonlySet<string>;
|
|
|
10
10
|
* made of letters, digits and inner hyphens.
|
|
11
11
|
*/
|
|
12
12
|
export declare const projectSlugSchema: z.ZodString;
|
|
13
|
+
/** The address a project's website is served at: its Project Slug's `camox.site` subdomain. */
|
|
14
|
+
export declare const projectWebsiteUrl: (slug: string) => string;
|
|
13
15
|
/** Why a slug can't be given to a new project. */
|
|
14
16
|
export type UnavailableSlugReason = "invalid" | "reserved" | "taken";
|
|
15
17
|
/** What a member is told when a slug can't be used, by reason. */
|
package/dist/projects.js
CHANGED
|
@@ -34,6 +34,8 @@ const RESERVED_PROJECT_SLUGS = /* @__PURE__ */ new Set([
|
|
|
34
34
|
* made of letters, digits and inner hyphens.
|
|
35
35
|
*/
|
|
36
36
|
const projectSlugSchema = /* @__PURE__ */ z.string().min(1, "Enter a slug").max(63, "Use at most 63 characters").regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use lowercase letters, digits and hyphens, without a hyphen at either end");
|
|
37
|
+
/** The address a project's website is served at: its Project Slug's `camox.site` subdomain. */
|
|
38
|
+
const projectWebsiteUrl = (slug) => `https://${slug}.camox.site`;
|
|
37
39
|
/** What a member is told when a slug can't be used, by reason. */
|
|
38
40
|
const UNAVAILABLE_SLUG_MESSAGES = {
|
|
39
41
|
invalid: "Use lowercase letters, digits and hyphens, without a hyphen at either end.",
|
|
@@ -60,4 +62,4 @@ function isHttpsUrl(value) {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
//#endregion
|
|
63
|
-
export { PROJECT_SETUP_STEPS, RESERVED_PROJECT_SLUGS, UNAVAILABLE_SLUG_MESSAGES, projectSlugSchema, socialProfileUrlSchema };
|
|
65
|
+
export { PROJECT_SETUP_STEPS, RESERVED_PROJECT_SLUGS, UNAVAILABLE_SLUG_MESSAGES, projectSlugSchema, projectWebsiteUrl, socialProfileUrlSchema };
|