@sanity/cross-dataset-duplicator 1.4.1 → 1.4.2
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 +4 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.esm.js +92 -35
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +92 -35
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/components/CrossDatasetDuplicator.tsx +1 -1
- package/src/components/Duplicator.tsx +3 -5
- package/src/components/DuplicatorQuery.tsx +3 -10
- package/src/components/DuplicatorWrapper.tsx +2 -3
- package/src/components/ResetSecret.tsx +6 -3
- package/src/context/ConfigProvider.tsx +1 -1
- package/src/helpers/constants.ts +2 -1
- package/src/plugin.tsx +1 -1
- package/src/types/index.ts +1 -0
- package/src/helpers/clientConfig.ts +0 -1
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Sanity Studio v3 Tool and Document Action for empowering content editors to migrate Documents and Assets between Sanity Datasets and Projects from inside the Studio.
|
|
4
4
|
|
|
5
|
+
> [!IMPORTANT]
|
|
6
|
+
> You may not need this plugin. It was developed long before Sanity had fully-featured [live preview, visual editing](https://www.sanity.io/docs/visual-editing/introduction-to-visual-editing), [perspectives](https://www.sanity.io/docs/content-lake/perspectives) and [content releases](https://www.sanity.io/docs/user-guides/content-releases) which are more seamless ways to stage and preview content before publishing into production. It is recommended you investigate these features first before using this plugin.
|
|
7
|
+
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
7
10
|
```
|
|
@@ -64,6 +67,7 @@ The plugin has some configuration options. These can be set by adding a config f
|
|
|
64
67
|
// Required settings to show document action
|
|
65
68
|
types: ['article', 'page'],
|
|
66
69
|
// Optional settings
|
|
70
|
+
apiVersion: '2025-02-19',
|
|
67
71
|
tool: true,
|
|
68
72
|
filter: '_type != "product"',
|
|
69
73
|
follow: [],
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {SVGProps} from 'react'
|
|
|
11
11
|
* Plugin: Cross Dataset Duplicator
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
export declare const crossDatasetDuplicator: Plugin_2<void | PluginConfig
|
|
14
|
+
export declare const crossDatasetDuplicator: Plugin_2<void | Partial<PluginConfig>>
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Component to perform a migration from the Cross Dataset Duplicator plugin
|
|
@@ -61,6 +61,7 @@ export declare const DuplicateToAction: {
|
|
|
61
61
|
* @public
|
|
62
62
|
*/
|
|
63
63
|
export declare interface PluginConfig {
|
|
64
|
+
apiVersion?: string
|
|
64
65
|
tool?: boolean
|
|
65
66
|
types?: string[]
|
|
66
67
|
filter?: string
|
|
@@ -77,6 +78,6 @@ declare type PreDefinedQuery = {
|
|
|
77
78
|
* Plugin config context hook from the Cross Dataset Duplicator plugin
|
|
78
79
|
* @public
|
|
79
80
|
*/
|
|
80
|
-
export declare function useCrossDatasetDuplicatorConfig(): PluginConfig
|
|
81
|
+
export declare function useCrossDatasetDuplicatorConfig(): Required<PluginConfig>
|
|
81
82
|
|
|
82
83
|
export {}
|
package/dist/index.esm.js
CHANGED
|
@@ -243,9 +243,26 @@ function Feedback(props) {
|
|
|
243
243
|
})
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
var __defProp$1 = Object.defineProperty;
|
|
247
|
+
var __defProps$1 = Object.defineProperties;
|
|
248
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
249
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
250
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
251
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
252
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
configurable: true,
|
|
255
|
+
writable: true,
|
|
256
|
+
value
|
|
257
|
+
}) : obj[key] = value;
|
|
258
|
+
var __spreadValues$1 = (a, b) => {
|
|
259
|
+
for (var prop in b || (b = {})) if (__hasOwnProp$2.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
260
|
+
if (__getOwnPropSymbols$2) for (var prop of __getOwnPropSymbols$2(b)) {
|
|
261
|
+
if (__propIsEnum$2.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
262
|
+
}
|
|
263
|
+
return a;
|
|
248
264
|
};
|
|
265
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
249
266
|
function Duplicator(props) {
|
|
250
267
|
var _a, _b, _c;
|
|
251
268
|
const {
|
|
@@ -255,11 +272,12 @@ function Duplicator(props) {
|
|
|
255
272
|
onDuplicated
|
|
256
273
|
} = props;
|
|
257
274
|
const isDarkMode = useTheme().sanity.color.dark;
|
|
258
|
-
const originClient = useClient(
|
|
275
|
+
const originClient = useClient({
|
|
276
|
+
apiVersion: pluginConfig.apiVersion
|
|
277
|
+
});
|
|
259
278
|
const schema = useSchema();
|
|
260
279
|
const workspaces = useWorkspaces();
|
|
261
|
-
const workspacesOptions = workspaces.map(workspace => ({
|
|
262
|
-
...workspace,
|
|
280
|
+
const workspacesOptions = workspaces.map(workspace => __spreadProps$1(__spreadValues$1({}, workspace), {
|
|
263
281
|
disabled: workspace.dataset === originClient.config().dataset && workspace.projectId === originClient.config().projectId
|
|
264
282
|
}));
|
|
265
283
|
const [destination, setDestination] = useState(workspaces.length ? (_a = workspacesOptions.find(space => !space.disabled)) != null ? _a : null : null);
|
|
@@ -308,7 +326,6 @@ function Duplicator(props) {
|
|
|
308
326
|
return doc._id;
|
|
309
327
|
});
|
|
310
328
|
const destinationClient = originClient.withConfig({
|
|
311
|
-
...clientConfig,
|
|
312
329
|
dataset: destination.dataset,
|
|
313
330
|
projectId: destination.projectId
|
|
314
331
|
});
|
|
@@ -322,8 +339,10 @@ function Duplicator(props) {
|
|
|
322
339
|
if (existingDoc._updatedAt === item.doc._updatedAt) {
|
|
323
340
|
item.status = "EXISTS";
|
|
324
341
|
} else if (existingDoc._updatedAt && item.doc._updatedAt) {
|
|
325
|
-
item.status = new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt) ?
|
|
326
|
-
|
|
342
|
+
item.status = new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt) ?
|
|
343
|
+
// Document at destination is newer
|
|
344
|
+
"OVERWRITE" :
|
|
345
|
+
// Document at destination is older
|
|
327
346
|
"UPDATE";
|
|
328
347
|
}
|
|
329
348
|
} else {
|
|
@@ -394,7 +413,7 @@ function Duplicator(props) {
|
|
|
394
413
|
tone: "transparent"
|
|
395
414
|
});
|
|
396
415
|
const destinationClient = originClient.withConfig({
|
|
397
|
-
|
|
416
|
+
apiVersion: pluginConfig.apiVersion,
|
|
398
417
|
dataset: destination.dataset,
|
|
399
418
|
projectId: destination.projectId
|
|
400
419
|
});
|
|
@@ -729,27 +748,26 @@ function DuplicatorQuery(props) {
|
|
|
729
748
|
pluginConfig
|
|
730
749
|
} = props;
|
|
731
750
|
const {
|
|
732
|
-
queries: preDefinedQueries
|
|
751
|
+
queries: preDefinedQueries,
|
|
752
|
+
apiVersion
|
|
733
753
|
} = pluginConfig;
|
|
734
|
-
const originClient = useClient(
|
|
754
|
+
const originClient = useClient({
|
|
755
|
+
apiVersion
|
|
756
|
+
});
|
|
735
757
|
const schema = useSchema();
|
|
736
758
|
const schemaTypes = schema.getTypeNames();
|
|
737
759
|
const [value, setValue] = useState("");
|
|
738
760
|
const [fetched, setFetched] = useState(false);
|
|
739
761
|
const [initialData, setInitialData] = useState({
|
|
740
762
|
docs: []
|
|
741
|
-
// draftIds: []
|
|
742
763
|
});
|
|
743
|
-
|
|
744
764
|
function handleSubmit(e) {
|
|
745
765
|
if (e) e.preventDefault();
|
|
746
766
|
originClient.fetch(value).then(res => {
|
|
747
767
|
const registeredAndPublishedDocs = res.length ? res.filter(doc => schemaTypes.includes(doc._type)).filter(doc => !doc._id.startsWith("drafts.")) : [];
|
|
748
768
|
setInitialData({
|
|
749
769
|
docs: registeredAndPublishedDocs
|
|
750
|
-
// draftIds: initialDraftIds
|
|
751
770
|
});
|
|
752
|
-
|
|
753
771
|
setFetched(true);
|
|
754
772
|
}).catch(err => console.error(err));
|
|
755
773
|
}
|
|
@@ -794,7 +812,7 @@ function DuplicatorQuery(props) {
|
|
|
794
812
|
fontSize: 2,
|
|
795
813
|
onChange: event => setValue(event.currentTarget.value),
|
|
796
814
|
padding: 4,
|
|
797
|
-
placeholder:
|
|
815
|
+
placeholder: '*[_type == "article"]',
|
|
798
816
|
value: value != null ? value : ""
|
|
799
817
|
})
|
|
800
818
|
}), /* @__PURE__ */jsx(Button, {
|
|
@@ -857,10 +875,13 @@ function DuplicatorWrapper(props) {
|
|
|
857
875
|
} = props;
|
|
858
876
|
const [inbound, setInbound] = useState([]);
|
|
859
877
|
const {
|
|
860
|
-
follow = []
|
|
878
|
+
follow = [],
|
|
879
|
+
apiVersion
|
|
861
880
|
} = pluginConfig;
|
|
862
881
|
const [mode, setMode] = useState(follow.length === 1 ? follow[0] : "outbound");
|
|
863
|
-
const client = useClient(
|
|
882
|
+
const client = useClient({
|
|
883
|
+
apiVersion
|
|
884
|
+
});
|
|
864
885
|
useEffect(() => {
|
|
865
886
|
(async () => {
|
|
866
887
|
if (follow.includes("inbound")) {
|
|
@@ -905,17 +926,23 @@ function DuplicatorWrapper(props) {
|
|
|
905
926
|
}
|
|
906
927
|
const SECRET_NAMESPACE = "CrossDatasetDuplicator";
|
|
907
928
|
const DEFAULT_CONFIG = {
|
|
929
|
+
apiVersion: "2025-02-19",
|
|
908
930
|
tool: true,
|
|
909
931
|
types: [],
|
|
910
932
|
filter: "",
|
|
911
933
|
follow: ["outbound"],
|
|
912
934
|
queries: []
|
|
913
935
|
};
|
|
914
|
-
function ResetSecret() {
|
|
915
|
-
|
|
936
|
+
function ResetSecret(_ref6) {
|
|
937
|
+
let {
|
|
938
|
+
apiVersion
|
|
939
|
+
} = _ref6;
|
|
940
|
+
const client = useClient({
|
|
941
|
+
apiVersion
|
|
942
|
+
});
|
|
916
943
|
const handleClick = useCallback(() => {
|
|
917
944
|
client.delete({
|
|
918
|
-
query:
|
|
945
|
+
query: '*[_id == "secrets.'.concat(SECRET_NAMESPACE, '"]')
|
|
919
946
|
});
|
|
920
947
|
}, [client]);
|
|
921
948
|
return /* @__PURE__ */jsx(Flex, {
|
|
@@ -933,16 +960,28 @@ function ResetSecret() {
|
|
|
933
960
|
})
|
|
934
961
|
});
|
|
935
962
|
}
|
|
963
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
964
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
965
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
966
|
+
var __objRest = (source, exclude) => {
|
|
967
|
+
var target = {};
|
|
968
|
+
for (var prop in source) if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
|
|
969
|
+
if (source != null && __getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(source)) {
|
|
970
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop)) target[prop] = source[prop];
|
|
971
|
+
}
|
|
972
|
+
return target;
|
|
973
|
+
};
|
|
936
974
|
const CrossDatasetDuplicatorContext = createContext(DEFAULT_CONFIG);
|
|
937
975
|
function useCrossDatasetDuplicatorConfig() {
|
|
938
976
|
const pluginConfig = useContext(CrossDatasetDuplicatorContext);
|
|
939
977
|
return pluginConfig;
|
|
940
978
|
}
|
|
941
979
|
function ConfigProvider(props) {
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
980
|
+
const _a = props,
|
|
981
|
+
{
|
|
982
|
+
pluginConfig
|
|
983
|
+
} = _a,
|
|
984
|
+
rest = __objRest(_a, ["pluginConfig"]);
|
|
946
985
|
return /* @__PURE__ */jsx(CrossDatasetDuplicatorContext.Provider, {
|
|
947
986
|
value: pluginConfig,
|
|
948
987
|
children: props.renderDefault(rest)
|
|
@@ -993,7 +1032,9 @@ function CrossDatasetDuplicator(props) {
|
|
|
993
1032
|
children: [/* @__PURE__ */jsx(DuplicatorQuery, {
|
|
994
1033
|
token: secrets == null ? void 0 : secrets.bearerToken,
|
|
995
1034
|
pluginConfig
|
|
996
|
-
}), /* @__PURE__ */jsx(ResetSecret, {
|
|
1035
|
+
}), /* @__PURE__ */jsx(ResetSecret, {
|
|
1036
|
+
apiVersion: pluginConfig.apiVersion
|
|
1037
|
+
})]
|
|
997
1038
|
});
|
|
998
1039
|
}
|
|
999
1040
|
if (!(docs == null ? void 0 : docs.length)) {
|
|
@@ -1070,12 +1111,29 @@ const crossDatasetDuplicatorTool = () => ({
|
|
|
1070
1111
|
docs: []
|
|
1071
1112
|
}
|
|
1072
1113
|
});
|
|
1114
|
+
var __defProp = Object.defineProperty;
|
|
1115
|
+
var __defProps = Object.defineProperties;
|
|
1116
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1117
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1118
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1119
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1120
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
1121
|
+
enumerable: true,
|
|
1122
|
+
configurable: true,
|
|
1123
|
+
writable: true,
|
|
1124
|
+
value
|
|
1125
|
+
}) : obj[key] = value;
|
|
1126
|
+
var __spreadValues = (a, b) => {
|
|
1127
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
1128
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
1129
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
1130
|
+
}
|
|
1131
|
+
return a;
|
|
1132
|
+
};
|
|
1133
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1073
1134
|
const crossDatasetDuplicator = definePlugin(function () {
|
|
1074
1135
|
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1075
|
-
const pluginConfig = {
|
|
1076
|
-
...DEFAULT_CONFIG,
|
|
1077
|
-
...config
|
|
1078
|
-
};
|
|
1136
|
+
const pluginConfig = __spreadValues(__spreadValues({}, DEFAULT_CONFIG), config);
|
|
1079
1137
|
const {
|
|
1080
1138
|
types
|
|
1081
1139
|
} = pluginConfig;
|
|
@@ -1084,17 +1142,16 @@ const crossDatasetDuplicator = definePlugin(function () {
|
|
|
1084
1142
|
tools: prev => pluginConfig.tool ? [...prev, crossDatasetDuplicatorTool()] : prev,
|
|
1085
1143
|
studio: {
|
|
1086
1144
|
components: {
|
|
1087
|
-
layout: props => ConfigProvider({
|
|
1088
|
-
...props,
|
|
1145
|
+
layout: props => ConfigProvider(__spreadProps(__spreadValues({}, props), {
|
|
1089
1146
|
pluginConfig
|
|
1090
|
-
})
|
|
1147
|
+
}))
|
|
1091
1148
|
}
|
|
1092
1149
|
},
|
|
1093
1150
|
document: {
|
|
1094
|
-
actions: (prev,
|
|
1151
|
+
actions: (prev, _ref7) => {
|
|
1095
1152
|
let {
|
|
1096
1153
|
schemaType
|
|
1097
|
-
} =
|
|
1154
|
+
} = _ref7;
|
|
1098
1155
|
return types && types.includes(schemaType) ? [...prev, DuplicateToAction] : prev;
|
|
1099
1156
|
}
|
|
1100
1157
|
}
|