@sanity/cross-dataset-duplicator 1.4.0 → 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/LICENSE +1 -1
- package/README.md +4 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.esm.js +93 -36
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +93 -36
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/components/CrossDatasetDuplicator.tsx +1 -1
- package/src/components/Duplicator.tsx +6 -6
- 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/dist/index.js
CHANGED
|
@@ -256,9 +256,26 @@ function Feedback(props) {
|
|
|
256
256
|
})
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
var __defProp$1 = Object.defineProperty;
|
|
260
|
+
var __defProps$1 = Object.defineProperties;
|
|
261
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
262
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
263
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
264
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
265
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
266
|
+
enumerable: true,
|
|
267
|
+
configurable: true,
|
|
268
|
+
writable: true,
|
|
269
|
+
value
|
|
270
|
+
}) : obj[key] = value;
|
|
271
|
+
var __spreadValues$1 = (a, b) => {
|
|
272
|
+
for (var prop in b || (b = {})) if (__hasOwnProp$2.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
273
|
+
if (__getOwnPropSymbols$2) for (var prop of __getOwnPropSymbols$2(b)) {
|
|
274
|
+
if (__propIsEnum$2.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
275
|
+
}
|
|
276
|
+
return a;
|
|
261
277
|
};
|
|
278
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
262
279
|
function Duplicator(props) {
|
|
263
280
|
var _a, _b, _c;
|
|
264
281
|
const {
|
|
@@ -268,12 +285,13 @@ function Duplicator(props) {
|
|
|
268
285
|
onDuplicated
|
|
269
286
|
} = props;
|
|
270
287
|
const isDarkMode = ui.useTheme().sanity.color.dark;
|
|
271
|
-
const originClient = sanity.useClient(
|
|
288
|
+
const originClient = sanity.useClient({
|
|
289
|
+
apiVersion: pluginConfig.apiVersion
|
|
290
|
+
});
|
|
272
291
|
const schema = sanity.useSchema();
|
|
273
292
|
const workspaces = sanity.useWorkspaces();
|
|
274
|
-
const workspacesOptions = workspaces.map(workspace => ({
|
|
275
|
-
|
|
276
|
-
disabled: workspace.dataset === originClient.config().dataset
|
|
293
|
+
const workspacesOptions = workspaces.map(workspace => __spreadProps$1(__spreadValues$1({}, workspace), {
|
|
294
|
+
disabled: workspace.dataset === originClient.config().dataset && workspace.projectId === originClient.config().projectId
|
|
277
295
|
}));
|
|
278
296
|
const [destination, setDestination] = React.useState(workspaces.length ? (_a = workspacesOptions.find(space => !space.disabled)) != null ? _a : null : null);
|
|
279
297
|
const [message, setMessage] = React.useState(null);
|
|
@@ -321,7 +339,6 @@ function Duplicator(props) {
|
|
|
321
339
|
return doc._id;
|
|
322
340
|
});
|
|
323
341
|
const destinationClient = originClient.withConfig({
|
|
324
|
-
...clientConfig,
|
|
325
342
|
dataset: destination.dataset,
|
|
326
343
|
projectId: destination.projectId
|
|
327
344
|
});
|
|
@@ -335,8 +352,10 @@ function Duplicator(props) {
|
|
|
335
352
|
if (existingDoc._updatedAt === item.doc._updatedAt) {
|
|
336
353
|
item.status = "EXISTS";
|
|
337
354
|
} else if (existingDoc._updatedAt && item.doc._updatedAt) {
|
|
338
|
-
item.status = new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt) ?
|
|
339
|
-
|
|
355
|
+
item.status = new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt) ?
|
|
356
|
+
// Document at destination is newer
|
|
357
|
+
"OVERWRITE" :
|
|
358
|
+
// Document at destination is older
|
|
340
359
|
"UPDATE";
|
|
341
360
|
}
|
|
342
361
|
} else {
|
|
@@ -407,7 +426,7 @@ function Duplicator(props) {
|
|
|
407
426
|
tone: "transparent"
|
|
408
427
|
});
|
|
409
428
|
const destinationClient = originClient.withConfig({
|
|
410
|
-
|
|
429
|
+
apiVersion: pluginConfig.apiVersion,
|
|
411
430
|
dataset: destination.dataset,
|
|
412
431
|
projectId: destination.projectId
|
|
413
432
|
});
|
|
@@ -742,27 +761,26 @@ function DuplicatorQuery(props) {
|
|
|
742
761
|
pluginConfig
|
|
743
762
|
} = props;
|
|
744
763
|
const {
|
|
745
|
-
queries: preDefinedQueries
|
|
764
|
+
queries: preDefinedQueries,
|
|
765
|
+
apiVersion
|
|
746
766
|
} = pluginConfig;
|
|
747
|
-
const originClient = sanity.useClient(
|
|
767
|
+
const originClient = sanity.useClient({
|
|
768
|
+
apiVersion
|
|
769
|
+
});
|
|
748
770
|
const schema = sanity.useSchema();
|
|
749
771
|
const schemaTypes = schema.getTypeNames();
|
|
750
772
|
const [value, setValue] = React.useState("");
|
|
751
773
|
const [fetched, setFetched] = React.useState(false);
|
|
752
774
|
const [initialData, setInitialData] = React.useState({
|
|
753
775
|
docs: []
|
|
754
|
-
// draftIds: []
|
|
755
776
|
});
|
|
756
|
-
|
|
757
777
|
function handleSubmit(e) {
|
|
758
778
|
if (e) e.preventDefault();
|
|
759
779
|
originClient.fetch(value).then(res => {
|
|
760
780
|
const registeredAndPublishedDocs = res.length ? res.filter(doc => schemaTypes.includes(doc._type)).filter(doc => !doc._id.startsWith("drafts.")) : [];
|
|
761
781
|
setInitialData({
|
|
762
782
|
docs: registeredAndPublishedDocs
|
|
763
|
-
// draftIds: initialDraftIds
|
|
764
783
|
});
|
|
765
|
-
|
|
766
784
|
setFetched(true);
|
|
767
785
|
}).catch(err => console.error(err));
|
|
768
786
|
}
|
|
@@ -807,7 +825,7 @@ function DuplicatorQuery(props) {
|
|
|
807
825
|
fontSize: 2,
|
|
808
826
|
onChange: event => setValue(event.currentTarget.value),
|
|
809
827
|
padding: 4,
|
|
810
|
-
placeholder:
|
|
828
|
+
placeholder: '*[_type == "article"]',
|
|
811
829
|
value: value != null ? value : ""
|
|
812
830
|
})
|
|
813
831
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
@@ -870,10 +888,13 @@ function DuplicatorWrapper(props) {
|
|
|
870
888
|
} = props;
|
|
871
889
|
const [inbound, setInbound] = React.useState([]);
|
|
872
890
|
const {
|
|
873
|
-
follow = []
|
|
891
|
+
follow = [],
|
|
892
|
+
apiVersion
|
|
874
893
|
} = pluginConfig;
|
|
875
894
|
const [mode, setMode] = React.useState(follow.length === 1 ? follow[0] : "outbound");
|
|
876
|
-
const client = sanity.useClient(
|
|
895
|
+
const client = sanity.useClient({
|
|
896
|
+
apiVersion
|
|
897
|
+
});
|
|
877
898
|
React.useEffect(() => {
|
|
878
899
|
(async () => {
|
|
879
900
|
if (follow.includes("inbound")) {
|
|
@@ -918,17 +939,23 @@ function DuplicatorWrapper(props) {
|
|
|
918
939
|
}
|
|
919
940
|
const SECRET_NAMESPACE = "CrossDatasetDuplicator";
|
|
920
941
|
const DEFAULT_CONFIG = {
|
|
942
|
+
apiVersion: "2025-02-19",
|
|
921
943
|
tool: true,
|
|
922
944
|
types: [],
|
|
923
945
|
filter: "",
|
|
924
946
|
follow: ["outbound"],
|
|
925
947
|
queries: []
|
|
926
948
|
};
|
|
927
|
-
function ResetSecret() {
|
|
928
|
-
|
|
949
|
+
function ResetSecret(_ref6) {
|
|
950
|
+
let {
|
|
951
|
+
apiVersion
|
|
952
|
+
} = _ref6;
|
|
953
|
+
const client = sanity.useClient({
|
|
954
|
+
apiVersion
|
|
955
|
+
});
|
|
929
956
|
const handleClick = React.useCallback(() => {
|
|
930
957
|
client.delete({
|
|
931
|
-
query:
|
|
958
|
+
query: '*[_id == "secrets.'.concat(SECRET_NAMESPACE, '"]')
|
|
932
959
|
});
|
|
933
960
|
}, [client]);
|
|
934
961
|
return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
@@ -946,16 +973,28 @@ function ResetSecret() {
|
|
|
946
973
|
})
|
|
947
974
|
});
|
|
948
975
|
}
|
|
976
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
977
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
978
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
979
|
+
var __objRest = (source, exclude) => {
|
|
980
|
+
var target = {};
|
|
981
|
+
for (var prop in source) if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
|
|
982
|
+
if (source != null && __getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(source)) {
|
|
983
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop)) target[prop] = source[prop];
|
|
984
|
+
}
|
|
985
|
+
return target;
|
|
986
|
+
};
|
|
949
987
|
const CrossDatasetDuplicatorContext = React.createContext(DEFAULT_CONFIG);
|
|
950
988
|
function useCrossDatasetDuplicatorConfig() {
|
|
951
989
|
const pluginConfig = React.useContext(CrossDatasetDuplicatorContext);
|
|
952
990
|
return pluginConfig;
|
|
953
991
|
}
|
|
954
992
|
function ConfigProvider(props) {
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
993
|
+
const _a = props,
|
|
994
|
+
{
|
|
995
|
+
pluginConfig
|
|
996
|
+
} = _a,
|
|
997
|
+
rest = __objRest(_a, ["pluginConfig"]);
|
|
959
998
|
return /* @__PURE__ */jsxRuntime.jsx(CrossDatasetDuplicatorContext.Provider, {
|
|
960
999
|
value: pluginConfig,
|
|
961
1000
|
children: props.renderDefault(rest)
|
|
@@ -1006,7 +1045,9 @@ function CrossDatasetDuplicator(props) {
|
|
|
1006
1045
|
children: [/* @__PURE__ */jsxRuntime.jsx(DuplicatorQuery, {
|
|
1007
1046
|
token: secrets == null ? void 0 : secrets.bearerToken,
|
|
1008
1047
|
pluginConfig
|
|
1009
|
-
}), /* @__PURE__ */jsxRuntime.jsx(ResetSecret, {
|
|
1048
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ResetSecret, {
|
|
1049
|
+
apiVersion: pluginConfig.apiVersion
|
|
1050
|
+
})]
|
|
1010
1051
|
});
|
|
1011
1052
|
}
|
|
1012
1053
|
if (!(docs == null ? void 0 : docs.length)) {
|
|
@@ -1083,12 +1124,29 @@ const crossDatasetDuplicatorTool = () => ({
|
|
|
1083
1124
|
docs: []
|
|
1084
1125
|
}
|
|
1085
1126
|
});
|
|
1127
|
+
var __defProp = Object.defineProperty;
|
|
1128
|
+
var __defProps = Object.defineProperties;
|
|
1129
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1130
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1131
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1132
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1133
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
1134
|
+
enumerable: true,
|
|
1135
|
+
configurable: true,
|
|
1136
|
+
writable: true,
|
|
1137
|
+
value
|
|
1138
|
+
}) : obj[key] = value;
|
|
1139
|
+
var __spreadValues = (a, b) => {
|
|
1140
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
1141
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
1142
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
1143
|
+
}
|
|
1144
|
+
return a;
|
|
1145
|
+
};
|
|
1146
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1086
1147
|
const crossDatasetDuplicator = sanity.definePlugin(function () {
|
|
1087
1148
|
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1088
|
-
const pluginConfig = {
|
|
1089
|
-
...DEFAULT_CONFIG,
|
|
1090
|
-
...config
|
|
1091
|
-
};
|
|
1149
|
+
const pluginConfig = __spreadValues(__spreadValues({}, DEFAULT_CONFIG), config);
|
|
1092
1150
|
const {
|
|
1093
1151
|
types
|
|
1094
1152
|
} = pluginConfig;
|
|
@@ -1097,17 +1155,16 @@ const crossDatasetDuplicator = sanity.definePlugin(function () {
|
|
|
1097
1155
|
tools: prev => pluginConfig.tool ? [...prev, crossDatasetDuplicatorTool()] : prev,
|
|
1098
1156
|
studio: {
|
|
1099
1157
|
components: {
|
|
1100
|
-
layout: props => ConfigProvider({
|
|
1101
|
-
...props,
|
|
1158
|
+
layout: props => ConfigProvider(__spreadProps(__spreadValues({}, props), {
|
|
1102
1159
|
pluginConfig
|
|
1103
|
-
})
|
|
1160
|
+
}))
|
|
1104
1161
|
}
|
|
1105
1162
|
},
|
|
1106
1163
|
document: {
|
|
1107
|
-
actions: (prev,
|
|
1164
|
+
actions: (prev, _ref7) => {
|
|
1108
1165
|
let {
|
|
1109
1166
|
schemaType
|
|
1110
|
-
} =
|
|
1167
|
+
} = _ref7;
|
|
1111
1168
|
return types && types.includes(schemaType) ? [...prev, DuplicateToAction] : prev;
|
|
1112
1169
|
}
|
|
1113
1170
|
}
|