@domandigital/sanity-copy 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,14 +1,35 @@
1
- # @domandigital/sanity-copy
2
-
3
- ## 0.2.0
4
-
5
- ### Minor Changes
6
-
7
- - 7765dda: First release. `withCopyCheck(schemaTypes)` adds the house copy check to every Sanity document type as validation warnings on the field that caused them, including inside Portable Text and image alt text. `checkDocumentCopy` runs the same check anywhere. The `sanity-copy` command sweeps a whole dataset (public, or private with `SANITY_API_TOKEN`) and lists findings by document and field. No Sanity dependency.
8
-
9
- ### Patch Changes
10
-
11
- - Updated dependencies [2b6f823]
12
- - Updated dependencies [7765dda]
13
- - Updated dependencies [ef5b85b]
14
- - @domandigital/craft@0.8.0
1
+ # @domandigital/sanity-copy
2
+
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cd13c94: `sanity-copy --claims` lists every price, figure, date and named source in a dataset, on its field, marked sourced or UNSOURCED, for a person to check against the primary source. `documentClaims(doc)` does the same in code.
8
+
9
+ ### Patch Changes
10
+
11
+ - cd13c94: `withCopyCheck` accepts a real Studio's schema types. Sanity declares its definitions as interfaces, which have no index signature, so the old `SchemaTypeLike` made `tsc` fail in the first Studio it was installed in.
12
+ - Updated dependencies [cd13c94]
13
+ - Updated dependencies [cd13c94]
14
+ - @domandigital/craft@0.10.0
15
+
16
+ ## 0.2.1
17
+
18
+ ### Patch Changes
19
+
20
+ - f57f546: `withCopyCheck` accepts a real Studio's schema types. Sanity declares its definitions as interfaces, which have no index signature, so the old `SchemaTypeLike` made `tsc` fail in the first Studio it was installed in.
21
+ - Updated dependencies [bbf1f54]
22
+ - @domandigital/craft@0.9.0
23
+
24
+ ## 0.2.0
25
+
26
+ ### Minor Changes
27
+
28
+ - 7765dda: First release. `withCopyCheck(schemaTypes)` adds the house copy check to every Sanity document type as validation warnings on the field that caused them, including inside Portable Text and image alt text. `checkDocumentCopy` runs the same check anywhere. The `sanity-copy` command sweeps a whole dataset (public, or private with `SANITY_API_TOKEN`) and lists findings by document and field. No Sanity dependency.
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [2b6f823]
33
+ - Updated dependencies [7765dda]
34
+ - Updated dependencies [ef5b85b]
35
+ - @domandigital/craft@0.8.0
package/LICENSE CHANGED
@@ -1,202 +1,202 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright 2026 Doman Digital Ltd
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Doman Digital Ltd
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,76 +1,89 @@
1
- # @domandigital/sanity-copy
2
-
3
- The Doman Digital house copy check inside Sanity Studio. Every document type
4
- gains craft's copy rules as validation **warnings**, on the exact field that
5
- caused them, including inside Portable Text. Publishing always still works:
6
- copy the owner types is advised on, never overridden.
7
-
8
- The rules are `COPY.md` in [`@domandigital/craft`](../craft). This package
9
- only decides which strings in a document are copy, and where each finding
10
- belongs.
11
-
12
- ## In a Studio
13
-
14
- Works in any Sanity Studio, v3 or later. Nothing in it is specific to one
15
- site. Two steps:
16
-
17
- 1. `pnpm add @domandigital/sanity-copy` (or npm, or yarn) in the Studio's app.
18
- 2. Wrap the types array in `sanity.config.ts`, as below.
19
-
20
- ```ts
21
- import { defineConfig } from "sanity";
22
- import { withCopyCheck } from "@domandigital/sanity-copy";
23
- import { schemaTypes } from "./schemas";
24
-
25
- export default defineConfig({
26
- // ...
27
- schema: { types: withCopyCheck(schemaTypes) },
28
- });
29
- ```
30
-
31
- An editor sees, on the field:
32
-
33
- > House rule (Em dash): "local businesses — built". Use a full stop, a comma,
34
- > or a colon.
35
-
36
- Why a wrapper and not a plugin: a plugin's `schema.types` function runs before
37
- the Studio's own types are added, so a plugin never sees them.
38
-
39
- Options, all optional:
40
-
41
- | Option | Default | What it does |
42
- | --- | --- | --- |
43
- | `excludeTypes` | `testimonial`, `review`, `proofQuote`, `quote` | Never checked. A person's own words are exempt from every house rule. |
44
- | `skipFields` | `slug`, `url`, `href`, `link`, `email`, `phone`, ids, enums | Never read, at any depth. |
45
- | `review` | `true` | Show the review and density tiers as well as the house rules. |
46
-
47
- What is read: strings, Portable Text (a block's spans joined, so a template
48
- split across spans is still caught), and the alt text and caption of images.
49
- What is not: slugs, links, references, enum values, asset data.
50
-
51
- ## Sweeping a whole dataset
52
-
53
- ```bash
54
- npx @domandigital/sanity-copy --project <id> # a public dataset
55
- SANITY_API_TOKEN=... npx @domandigital/sanity-copy --project <id> --types homepage,service
56
- npx @domandigital/sanity-copy --file export.json --json
57
- ```
58
-
59
- Findings are listed per document and field. Exit **0** no house-rule finding,
60
- **1** at least one, **2** nothing was checked. A token is read from the
61
- environment, never a flag. It reports and changes nothing.
62
-
63
- ## In code
64
-
65
- ```ts
66
- import { checkDocumentCopy, pathToString, describeFinding } from "@domandigital/sanity-copy";
67
-
68
- for (const f of checkDocumentCopy(doc)) console.log(pathToString(f.path), describeFinding(f));
69
- ```
70
-
71
- No Sanity dependency, and nothing a Studio imports touches Node, so the same
72
- check runs in the Studio, a script and a test.
73
-
74
- ## Licence
75
-
76
- Apache-2.0.
1
+ # @domandigital/sanity-copy
2
+
3
+ The Doman Digital house copy check inside Sanity Studio. Every document type
4
+ gains craft's copy rules as validation **warnings**, on the exact field that
5
+ caused them, including inside Portable Text. Publishing always still works:
6
+ copy the owner types is advised on, never overridden.
7
+
8
+ The rules are `COPY.md` in [`@domandigital/craft`](../craft). This package
9
+ only decides which strings in a document are copy, and where each finding
10
+ belongs.
11
+
12
+ ## In a Studio
13
+
14
+ Works in any Sanity Studio, v3 or later. Nothing in it is specific to one
15
+ site. Two steps:
16
+
17
+ 1. `pnpm add @domandigital/sanity-copy` (or npm, or yarn) in the Studio's app.
18
+ 2. Wrap the types array in `sanity.config.ts`, as below.
19
+
20
+ ```ts
21
+ import { defineConfig } from "sanity";
22
+ import { withCopyCheck } from "@domandigital/sanity-copy";
23
+ import { schemaTypes } from "./schemas";
24
+
25
+ export default defineConfig({
26
+ // ...
27
+ schema: { types: withCopyCheck(schemaTypes) },
28
+ });
29
+ ```
30
+
31
+ An editor sees, on the field:
32
+
33
+ > House rule (Em dash): "local businesses — built". Use a full stop, a comma,
34
+ > or a colon.
35
+
36
+ Why a wrapper and not a plugin: a plugin's `schema.types` function runs before
37
+ the Studio's own types are added, so a plugin never sees them.
38
+
39
+ Options, all optional:
40
+
41
+ | Option | Default | What it does |
42
+ | --- | --- | --- |
43
+ | `excludeTypes` | `testimonial`, `review`, `proofQuote`, `quote` | Never checked. A person's own words are exempt from every house rule. |
44
+ | `skipFields` | `slug`, `url`, `href`, `link`, `email`, `phone`, ids, enums | Never read, at any depth. |
45
+ | `review` | `true` | Show the review and density tiers as well as the house rules. |
46
+
47
+ What is read: strings, Portable Text (a block's spans joined, so a template
48
+ split across spans is still caught), and the alt text and caption of images.
49
+ What is not: slugs, links, references, enum values, asset data.
50
+
51
+ ## Sweeping a whole dataset
52
+
53
+ ```bash
54
+ npx @domandigital/sanity-copy --project <id> # a public dataset
55
+ SANITY_API_TOKEN=... npx @domandigital/sanity-copy --project <id> --types homepage,service
56
+ npx @domandigital/sanity-copy --file export.json --json
57
+ ```
58
+
59
+ Findings are listed per document and field. Exit **0** no house-rule finding,
60
+ **1** at least one, **2** nothing was checked. A token is read from the
61
+ environment, never a flag. It reports and changes nothing.
62
+
63
+ ## The claims list
64
+
65
+ ```bash
66
+ npx @domandigital/sanity-copy --project <id> --claims
67
+ ```
68
+
69
+ No style rule can say whether a figure is true. `--claims` lists every
70
+ sentence holding a price, a figure, a date or a named source, on its field,
71
+ marked `sourced` (a source is named, in the sentence or a footnote) or
72
+ `UNSOURCED`. Check each against its primary source, then source it, correct it
73
+ or cut it. It always exits 0: a checklist, not a verdict. `documentClaims(doc)`
74
+ does the same in code.
75
+
76
+ ## In code
77
+
78
+ ```ts
79
+ import { checkDocumentCopy, pathToString, describeFinding } from "@domandigital/sanity-copy";
80
+
81
+ for (const f of checkDocumentCopy(doc)) console.log(pathToString(f.path), describeFinding(f));
82
+ ```
83
+
84
+ No Sanity dependency, and nothing a Studio imports touches Node, so the same
85
+ check runs in the Studio, a script and a test.
86
+
87
+ ## Licence
88
+
89
+ Apache-2.0.
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { readFileSync } from "fs";
5
5
 
6
6
  // src/core.ts
7
- import { applyHouseGate, checkCopy } from "@domandigital/craft";
7
+ import { applyHouseGate, checkCopy, findClaims } from "@domandigital/craft";
8
8
  var DEFAULT_EXCLUDED_TYPES = ["testimonial", "review", "proofQuote", "quote"];
9
9
  var DEFAULT_SKIP_FIELDS = [
10
10
  "slug",
@@ -113,6 +113,17 @@ function checkDocumentCopy(doc, options = {}) {
113
113
  }
114
114
  return findings;
115
115
  }
116
+ function documentClaims(doc, options = {}) {
117
+ if (!isRecord(doc)) return [];
118
+ const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
119
+ if (typeof doc._type === "string" && excluded.has(doc._type)) return [];
120
+ const pieces = collectCopy(doc, options);
121
+ const { claims } = findClaims(pieces.map((p, i) => ({ path: fileFor(i), text: p.text })));
122
+ return claims.flatMap(({ path, line: _line, ...claim }) => {
123
+ const piece = pieces[Number(/^field-(\d+)\.md$/.exec(path)?.[1])];
124
+ return piece ? [{ ...claim, path: piece.path }] : [];
125
+ });
126
+ }
116
127
  function describeFinding(f) {
117
128
  const lead = f.tier === "block" ? "House rule" : "Worth a look";
118
129
  return `${lead} (${f.name}): ${f.message}. ${f.fix}`;
@@ -123,7 +134,7 @@ function pathToString(path) {
123
134
 
124
135
  // src/cli.ts
125
136
  function parse(argv) {
126
- const args = { dataset: "production", json: false };
137
+ const args = { dataset: "production", json: false, claims: false };
127
138
  for (let i = 0; i < argv.length; i += 1) {
128
139
  const a = argv[i];
129
140
  const value = () => {
@@ -136,6 +147,7 @@ function parse(argv) {
136
147
  else if (a === "--types") args.types = value().split(",").map((t) => t.trim()).filter(Boolean);
137
148
  else if (a === "--file") args.file = value();
138
149
  else if (a === "--json") args.json = true;
150
+ else if (a === "--claims") args.claims = true;
139
151
  else if (a === "--help" || a === "-h") return "help";
140
152
  else return `unknown option ${a}`;
141
153
  }
@@ -171,7 +183,9 @@ var label = (doc) => {
171
183
  async function main(argv, out = console.log, err = console.error) {
172
184
  const args = parse(argv);
173
185
  if (args === "help") {
174
- out("usage: sanity-copy --project <id> [--dataset production] [--types a,b] [--json]\n sanity-copy --file export.json [--json]");
186
+ out(
187
+ "usage: sanity-copy --project <id> [--dataset production] [--types a,b] [--claims] [--json]\n sanity-copy --file export.json [--claims] [--json]\n--claims lists every price, figure, date and named source, sourced or UNSOURCED, to check by hand."
188
+ );
175
189
  return 0;
176
190
  }
177
191
  if (typeof args === "string") {
@@ -189,6 +203,7 @@ async function main(argv, out = console.log, err = console.error) {
189
203
  err("sanity-copy: the dataset returned 0 documents. Nothing was checked.");
190
204
  return 2;
191
205
  }
206
+ if (args.claims) return reportClaims(docs, args.json, out);
192
207
  const results = [];
193
208
  for (const doc of docs) {
194
209
  const findings = checkDocumentCopy(doc);
@@ -209,6 +224,35 @@ sanity-copy: ${docs.length} documents, ${block} house-rule finding${block === 1
209
224
  }
210
225
  return block > 0 ? 1 : 0;
211
226
  }
227
+ function reportClaims(docs, json, out) {
228
+ const results = [];
229
+ for (const doc of docs) {
230
+ const claims = documentClaims(doc);
231
+ if (claims.length) results.push({ doc: label(doc), claims });
232
+ }
233
+ const all = results.flatMap((r) => r.claims);
234
+ const unsourced = all.filter((c) => c.sources.length === 0).length;
235
+ if (json) {
236
+ out(JSON.stringify({ documents: docs.length, claims: all.length, unsourced, results }, null, 2));
237
+ return 0;
238
+ }
239
+ for (const r of results) {
240
+ out(r.doc);
241
+ for (const c of r.claims) {
242
+ const what = [
243
+ ...c.facts.map((f) => f.value),
244
+ ...c.sources.map((s) => `source: ${s}`),
245
+ ...c.nearby ? [`${c.nearby.join(", ")} named earlier in the paragraph: does it cover this?`] : []
246
+ ].join(" \xB7 ");
247
+ out(` ${pathToString(c.path)} ${c.sources.length ? "sourced " : "UNSOURCED"} ${what}`);
248
+ out(` ${c.sentence}`);
249
+ }
250
+ }
251
+ out(`
252
+ sanity-copy --claims: ${docs.length} documents, ${all.length} claim${all.length === 1 ? "" : "s"} to check, ${unsourced} with no source named.`);
253
+ out("Check each against its primary source. Sourced means a source is named, not that it agrees.");
254
+ return 0;
255
+ }
212
256
  var invoked = process.argv[1] ?? "";
213
257
  if (/sanity-copy|cli\.(?:c?js|ts)$/.test(invoked)) {
214
258
  main(process.argv.slice(2)).then((code) => process.exit(code));
package/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ __export(index_exports, {
26
26
  collectCopy: () => collectCopy,
27
27
  copyCheckRule: () => copyCheckRule,
28
28
  describeFinding: () => describeFinding,
29
+ documentClaims: () => documentClaims,
29
30
  pathToString: () => pathToString,
30
31
  withCopyCheck: () => withCopyCheck
31
32
  });
@@ -141,6 +142,17 @@ function checkDocumentCopy(doc, options = {}) {
141
142
  }
142
143
  return findings;
143
144
  }
145
+ function documentClaims(doc, options = {}) {
146
+ if (!isRecord(doc)) return [];
147
+ const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
148
+ if (typeof doc._type === "string" && excluded.has(doc._type)) return [];
149
+ const pieces = collectCopy(doc, options);
150
+ const { claims } = (0, import_craft.findClaims)(pieces.map((p, i) => ({ path: fileFor(i), text: p.text })));
151
+ return claims.flatMap(({ path, line: _line, ...claim }) => {
152
+ const piece = pieces[Number(/^field-(\d+)\.md$/.exec(path)?.[1])];
153
+ return piece ? [{ ...claim, path: piece.path }] : [];
154
+ });
155
+ }
144
156
  function describeFinding(f) {
145
157
  const lead = f.tier === "block" ? "House rule" : "Worth a look";
146
158
  return `${lead} (${f.name}): ${f.message}. ${f.fix}`;
@@ -164,7 +176,7 @@ function copyCheckRule(rule, options = {}) {
164
176
  }
165
177
  var asArray = (v) => v === void 0 || v === null ? [] : Array.isArray(v) ? v : [v];
166
178
  function withCopyCheck(types, options = {}) {
167
- const excluded = new Set(options.excludeTypes ?? ["testimonial", "review", "proofQuote", "quote"]);
179
+ const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
168
180
  return types.map((t) => {
169
181
  if (t.type !== "document" || excluded.has(t.name)) return t;
170
182
  const existing = t.validation;
@@ -183,6 +195,7 @@ function withCopyCheck(types, options = {}) {
183
195
  collectCopy,
184
196
  copyCheckRule,
185
197
  describeFinding,
198
+ documentClaims,
186
199
  pathToString,
187
200
  withCopyCheck
188
201
  });
package/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Claim } from '@domandigital/craft';
2
+
1
3
  /**
2
4
  * The house copy check over a Sanity document.
3
5
  *
@@ -6,6 +8,7 @@
6
8
  * the same answer in all three. The rules are craft's: this file only decides
7
9
  * which strings in a document are copy, and where each finding belongs.
8
10
  */
11
+
9
12
  /** A Studio path: field names, array indices, or `{ _key }` for keyed array items. */
10
13
  type PathSegment = string | number | {
11
14
  _key: string;
@@ -48,6 +51,17 @@ interface Piece {
48
51
  declare function collectCopy(doc: unknown, options?: CopyCheckOptions): Piece[];
49
52
  /** Check one document. Returns nothing for an excluded type. */
50
53
  declare function checkDocumentCopy(doc: unknown, options?: CopyCheckOptions): CopyFinding[];
54
+ interface DocumentClaim extends Omit<Claim, "path" | "line"> {
55
+ /** The field the sentence is in. */
56
+ path: Path;
57
+ }
58
+ /**
59
+ * Every sentence in a document holding a price, figure, date or named source,
60
+ * for a person to check against the primary source. craft's claims list, with
61
+ * each claim on the field an editor would open. Excluded types are skipped, as
62
+ * for the copy check: a client's own words are verified with them, not here.
63
+ */
64
+ declare function documentClaims(doc: unknown, options?: CopyCheckOptions): DocumentClaim[];
51
65
  /** One line an editor can act on. */
52
66
  declare function describeFinding(f: CopyFinding): string;
53
67
  /** A path as text, for a report: `hero.title`, `body[_key=="a1"]`. */
@@ -80,12 +94,15 @@ interface RuleLike {
80
94
  }[]): RuleLike;
81
95
  warning(message?: string): RuleLike;
82
96
  }
83
- /** The part of a Sanity schema type definition this reads. */
97
+ /**
98
+ * The part of a Sanity schema type definition this reads. No index signature:
99
+ * Sanity declares its definitions as interfaces, which have none, so one here
100
+ * would reject every real Studio's types.
101
+ */
84
102
  interface SchemaTypeLike {
85
103
  name: string;
86
104
  type: string;
87
105
  validation?: unknown;
88
- [key: string]: unknown;
89
106
  }
90
107
  /**
91
108
  * The custom rule, on its own, for a Studio that composes validation itself:
@@ -95,4 +112,4 @@ declare function copyCheckRule(rule: RuleLike, options?: CopyCheckOptions): Rule
95
112
  /** Every document type gains the copy check as a warning, beside the validation it already has. */
96
113
  declare function withCopyCheck<T extends SchemaTypeLike>(types: T[], options?: CopyCheckOptions): T[];
97
114
 
98
- export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, pathToString, withCopyCheck };
115
+ export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type DocumentClaim, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, documentClaims, pathToString, withCopyCheck };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Claim } from '@domandigital/craft';
2
+
1
3
  /**
2
4
  * The house copy check over a Sanity document.
3
5
  *
@@ -6,6 +8,7 @@
6
8
  * the same answer in all three. The rules are craft's: this file only decides
7
9
  * which strings in a document are copy, and where each finding belongs.
8
10
  */
11
+
9
12
  /** A Studio path: field names, array indices, or `{ _key }` for keyed array items. */
10
13
  type PathSegment = string | number | {
11
14
  _key: string;
@@ -48,6 +51,17 @@ interface Piece {
48
51
  declare function collectCopy(doc: unknown, options?: CopyCheckOptions): Piece[];
49
52
  /** Check one document. Returns nothing for an excluded type. */
50
53
  declare function checkDocumentCopy(doc: unknown, options?: CopyCheckOptions): CopyFinding[];
54
+ interface DocumentClaim extends Omit<Claim, "path" | "line"> {
55
+ /** The field the sentence is in. */
56
+ path: Path;
57
+ }
58
+ /**
59
+ * Every sentence in a document holding a price, figure, date or named source,
60
+ * for a person to check against the primary source. craft's claims list, with
61
+ * each claim on the field an editor would open. Excluded types are skipped, as
62
+ * for the copy check: a client's own words are verified with them, not here.
63
+ */
64
+ declare function documentClaims(doc: unknown, options?: CopyCheckOptions): DocumentClaim[];
51
65
  /** One line an editor can act on. */
52
66
  declare function describeFinding(f: CopyFinding): string;
53
67
  /** A path as text, for a report: `hero.title`, `body[_key=="a1"]`. */
@@ -80,12 +94,15 @@ interface RuleLike {
80
94
  }[]): RuleLike;
81
95
  warning(message?: string): RuleLike;
82
96
  }
83
- /** The part of a Sanity schema type definition this reads. */
97
+ /**
98
+ * The part of a Sanity schema type definition this reads. No index signature:
99
+ * Sanity declares its definitions as interfaces, which have none, so one here
100
+ * would reject every real Studio's types.
101
+ */
84
102
  interface SchemaTypeLike {
85
103
  name: string;
86
104
  type: string;
87
105
  validation?: unknown;
88
- [key: string]: unknown;
89
106
  }
90
107
  /**
91
108
  * The custom rule, on its own, for a Studio that composes validation itself:
@@ -95,4 +112,4 @@ declare function copyCheckRule(rule: RuleLike, options?: CopyCheckOptions): Rule
95
112
  /** Every document type gains the copy check as a warning, beside the validation it already has. */
96
113
  declare function withCopyCheck<T extends SchemaTypeLike>(types: T[], options?: CopyCheckOptions): T[];
97
114
 
98
- export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, pathToString, withCopyCheck };
115
+ export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type DocumentClaim, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, documentClaims, pathToString, withCopyCheck };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/core.ts
2
- import { applyHouseGate, checkCopy } from "@domandigital/craft";
2
+ import { applyHouseGate, checkCopy, findClaims } from "@domandigital/craft";
3
3
  var DEFAULT_EXCLUDED_TYPES = ["testimonial", "review", "proofQuote", "quote"];
4
4
  var DEFAULT_SKIP_FIELDS = [
5
5
  "slug",
@@ -108,6 +108,17 @@ function checkDocumentCopy(doc, options = {}) {
108
108
  }
109
109
  return findings;
110
110
  }
111
+ function documentClaims(doc, options = {}) {
112
+ if (!isRecord(doc)) return [];
113
+ const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
114
+ if (typeof doc._type === "string" && excluded.has(doc._type)) return [];
115
+ const pieces = collectCopy(doc, options);
116
+ const { claims } = findClaims(pieces.map((p, i) => ({ path: fileFor(i), text: p.text })));
117
+ return claims.flatMap(({ path, line: _line, ...claim }) => {
118
+ const piece = pieces[Number(/^field-(\d+)\.md$/.exec(path)?.[1])];
119
+ return piece ? [{ ...claim, path: piece.path }] : [];
120
+ });
121
+ }
111
122
  function describeFinding(f) {
112
123
  const lead = f.tier === "block" ? "House rule" : "Worth a look";
113
124
  return `${lead} (${f.name}): ${f.message}. ${f.fix}`;
@@ -131,7 +142,7 @@ function copyCheckRule(rule, options = {}) {
131
142
  }
132
143
  var asArray = (v) => v === void 0 || v === null ? [] : Array.isArray(v) ? v : [v];
133
144
  function withCopyCheck(types, options = {}) {
134
- const excluded = new Set(options.excludeTypes ?? ["testimonial", "review", "proofQuote", "quote"]);
145
+ const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
135
146
  return types.map((t) => {
136
147
  if (t.type !== "document" || excluded.has(t.name)) return t;
137
148
  const existing = t.validation;
@@ -149,6 +160,7 @@ export {
149
160
  collectCopy,
150
161
  copyCheckRule,
151
162
  describeFinding,
163
+ documentClaims,
152
164
  pathToString,
153
165
  withCopyCheck
154
166
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domandigital/sanity-copy",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "description": "The Doman Digital house copy check in Sanity Studio: every document type gains craft's copy rules as validation warnings on the field that caused them. Also a pure checker for a document or an export. No Sanity dependency.",
6
6
  "license": "Apache-2.0",
@@ -47,7 +47,7 @@
47
47
  "provenance": true
48
48
  },
49
49
  "dependencies": {
50
- "@domandigital/craft": "^0.8.0"
50
+ "@domandigital/craft": "^0.10.0"
51
51
  },
52
52
  "keywords": [
53
53
  "sanity",