@mintlify/common 1.0.1043 → 1.0.1045
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/getRelativeRecordName.d.ts +2 -0
- package/dist/getRelativeRecordName.js +19 -0
- package/dist/getRelativeRecordName.test.d.ts +1 -0
- package/dist/getRelativeRecordName.test.js +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Approximates the registrable apex as the last two labels — accurate for
|
|
2
|
+
// gTLDs like .com/.io/.dev; ccTLDs like .co.uk are not handled.
|
|
3
|
+
export const getApexDomain = (domain) => {
|
|
4
|
+
const labels = domain.split('.');
|
|
5
|
+
if (labels.length < 2)
|
|
6
|
+
return domain;
|
|
7
|
+
return labels.slice(-2).join('.');
|
|
8
|
+
};
|
|
9
|
+
// Most DNS providers append the zone (apex) to the Name field automatically,
|
|
10
|
+
// so users only enter the relative portion (e.g. `docs` for `docs.example.com`).
|
|
11
|
+
export const getRelativeRecordName = (recordDomain, customDomain) => {
|
|
12
|
+
const apex = getApexDomain(customDomain);
|
|
13
|
+
if (recordDomain === apex)
|
|
14
|
+
return '@';
|
|
15
|
+
if (recordDomain.endsWith(`.${apex}`)) {
|
|
16
|
+
return recordDomain.slice(0, -(apex.length + 1));
|
|
17
|
+
}
|
|
18
|
+
return recordDomain;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getRelativeRecordName } from './getRelativeRecordName.js';
|
|
3
|
+
describe('getRelativeRecordName', () => {
|
|
4
|
+
it('strips the apex from a subdomain CNAME', () => {
|
|
5
|
+
expect(getRelativeRecordName('docs.example.com', 'docs.example.com')).toBe('docs');
|
|
6
|
+
});
|
|
7
|
+
it('strips the apex from a deeper TXT record', () => {
|
|
8
|
+
expect(getRelativeRecordName('_cf-custom-hostname.docs.example.com', 'docs.example.com')).toBe('_cf-custom-hostname.docs');
|
|
9
|
+
});
|
|
10
|
+
it('returns "@" when the record sits at the apex', () => {
|
|
11
|
+
expect(getRelativeRecordName('example.com', 'example.com')).toBe('@');
|
|
12
|
+
});
|
|
13
|
+
it('preserves multi-level subdomains under the apex', () => {
|
|
14
|
+
expect(getRelativeRecordName('docs.team.example.com', 'docs.team.example.com')).toBe('docs.team');
|
|
15
|
+
});
|
|
16
|
+
it('returns the original record when it is outside the apex', () => {
|
|
17
|
+
expect(getRelativeRecordName('something.elsewhere.com', 'docs.example.com')).toBe('something.elsewhere.com');
|
|
18
|
+
});
|
|
19
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from './truncateAtWordBoundary.js';
|
|
|
28
28
|
export * from './api-reference/parseApiTargetFromMetadata.js';
|
|
29
29
|
export * from './mintIgnore.js';
|
|
30
30
|
export * from './getDisplayDomain.js';
|
|
31
|
+
export * from './getRelativeRecordName.js';
|
|
31
32
|
export * from './basePaths.js';
|
|
32
33
|
export * from './exponentialBackoff.js';
|
|
33
34
|
export * from './isOrgLessThanTwoWeeksOld.js';
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export * from './truncateAtWordBoundary.js';
|
|
|
28
28
|
export * from './api-reference/parseApiTargetFromMetadata.js';
|
|
29
29
|
export * from './mintIgnore.js';
|
|
30
30
|
export * from './getDisplayDomain.js';
|
|
31
|
+
export * from './getRelativeRecordName.js';
|
|
31
32
|
export * from './basePaths.js';
|
|
32
33
|
export * from './exponentialBackoff.js';
|
|
33
34
|
export * from './isOrgLessThanTwoWeeksOld.js';
|