directus-extension-phone-field 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vincent Cottalorda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # Directus Phone Field
2
+
3
+ Phone number field for Directus: country selector, as-you-type formatting, E.164 storage and server-side validation.
4
+
5
+ Built on [libphonenumber-js](https://gitlab.com/catamphetamine/libphonenumber-js) (`max` metadata: numbers are validated against real number ranges per country, not just their length).
6
+
7
+ ## Features
8
+
9
+ This bundle ships three extensions that work together.
10
+
11
+ ### Interface — `Phone`
12
+
13
+ - Country selector with flags, localized country names and calling codes.
14
+ - As-you-type formatting in the national format of the selected country.
15
+ - Typing an international number (`+44…`) switches the selector to the detected country.
16
+ - Input longer than the country's maximum length is rejected.
17
+ - Invalid numbers are highlighted once the field loses focus.
18
+ - Stores the number in [E.164](https://en.wikipedia.org/wiki/E.164) format (`+33612345678`).
19
+
20
+ Options:
21
+
22
+ | Option | Description |
23
+ | ------------------- | ----------------------------------------------------------------- |
24
+ | Default country | Country preselected when the field is empty. |
25
+ | Preferred countries | Countries listed first in the selector, above the full list. |
26
+
27
+ ### Display — `Phone`
28
+
29
+ Shows the number with its country flag, as a clickable `tel:` link.
30
+
31
+ | Option | Description |
32
+ | ------ | ------------------------------------------------------------------ |
33
+ | Format | `International` (`+33 6 12 34 56 78`) or `National` (`06 12 34 56 78`). |
34
+
35
+ ### Hook — server-side validation
36
+
37
+ Applies to every field using the `Phone` interface, on item create and update, whatever the source (app, REST, GraphQL, SDK, flows):
38
+
39
+ - Normalizes the value to E.164.
40
+ - Rejects invalid numbers with a native `FAILED_VALIDATION` error.
41
+ - Adds a default note to the field describing the expected format, unless one is already set.
42
+
43
+ Accepted write formats:
44
+
45
+ ```jsonc
46
+ "+33 6 12 34 56 78" // any international format
47
+ "+33612345678" // E.164
48
+ { "country": "FR", "number": "06 12 34 56 78" } // national number with its country
49
+ ```
50
+
51
+ A national number without a country (`"06 12 34 56 78"`) is rejected, since its country cannot be inferred.
52
+
53
+ ## Requirements
54
+
55
+ - Directus `^12.0.0`
56
+ - A `string` field
57
+
58
+ ## Installation
59
+
60
+ ### Marketplace
61
+
62
+ This bundle contains a non-sandboxed API hook: installing it from the Marketplace requires `MARKETPLACE_TRUST=all` on your Directus instance.
63
+
64
+ ### Manual
65
+
66
+ ```sh
67
+ npm install directus-extension-phone-field
68
+ ```
69
+
70
+ Or copy the built extension (`package.json` and `dist/`) into your `extensions` folder, then restart Directus.
71
+
72
+ ## Usage
73
+
74
+ 1. Create a `string` field (or edit an existing one).
75
+ 2. Select the `Phone` interface and configure the default and preferred countries.
76
+ 3. Select the `Phone` display to render the number in layouts and relations.
77
+
78
+ ## Development
79
+
80
+ ```sh
81
+ pnpm install
82
+ pnpm dev # build in watch mode
83
+ pnpm build
84
+ pnpm type-check
85
+ pnpm validate
86
+ ```
87
+
88
+ ## License
89
+
90
+ [MIT](./LICENSE)