@shipstatic/drop 2.10.3 → 2.10.4-beta.10

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/index.js CHANGED
@@ -180,6 +180,35 @@ function hasUnbuiltMarker(filePath2) {
180
180
  const segments = filePath2.replace(/\\/g, "/").split("/").filter(Boolean);
181
181
  return segments.some((s) => UNBUILT_PROJECT_MARKERS.has(s));
182
182
  }
183
+ var BILLING_RETURNS = {
184
+ checkout: ["upgrading", "true"],
185
+ portal: ["billing", "returned"]
186
+ };
187
+ var marker = (kind) => BILLING_RETURNS[kind].join("=");
188
+ function consolePaths(account) {
189
+ const base = "";
190
+ const at = (path) => `${base}${path}`;
191
+ return {
192
+ dashboard: () => "/",
193
+ newSite: () => at("/new"),
194
+ deployments: Object.assign(() => at("/deployments"), {
195
+ upload: () => at("/deployments/upload")
196
+ }),
197
+ domains: Object.assign(() => at("/domains"), {
198
+ connect: (domain) => at(`/domains/${domain}/connect`),
199
+ deployment: (domain) => at(`/domains/${domain}/deployment`)
200
+ }),
201
+ settings: (fragment) => at(fragment ? `/settings#${fragment}` : "/settings"),
202
+ /** Settings, marked as the landing of a Stripe Customer Portal return. */
203
+ settingsAfterBilling: () => at(`/settings?${marker("portal")}`),
204
+ upgrade: (plan) => at(plan ? `/upgrade/${plan}` : "/upgrade"),
205
+ success: () => at("/success"),
206
+ /** The success page, marked as the landing of a Stripe Checkout return. */
207
+ successAfterCheckout: () => at(`/success?${marker("checkout")}`),
208
+ apiKey: () => at("/api-key")
209
+ };
210
+ }
211
+ `https://my.shipstatic.com${consolePaths().apiKey()}`;
183
212
  var FileValidationStatus = {
184
213
  /** File is pending validation */
185
214
  PENDING: "pending",
@@ -1079,7 +1108,7 @@ var initialState = {
1079
1108
  };
1080
1109
  function useDrop({ ship }) {
1081
1110
  const [state, setState] = useState(initialState);
1082
- const isProcessingRef = useRef(false);
1111
+ const runRef = useRef(null);
1083
1112
  const folderInputRef = useRef(null);
1084
1113
  const filesInputRef = useRef(null);
1085
1114
  const isProcessing = state.phase === "processing";
@@ -1090,24 +1119,40 @@ function useDrop({ ship }) {
1090
1119
  [state.files]
1091
1120
  );
1092
1121
  const getFilesForUpload = useCallback(() => validFiles.map((f) => f.file), [validFiles]);
1093
- const processFiles2 = useCallback(
1094
- async (newFiles) => {
1095
- if (isProcessingRef.current) {
1122
+ const prepare = useCallback(
1123
+ async (collect) => {
1124
+ if (runRef.current) {
1096
1125
  console.warn("File processing already in progress. Ignoring duplicate call.");
1097
1126
  return;
1098
1127
  }
1099
- if (!newFiles || newFiles.length === 0) return;
1100
- isProcessingRef.current = true;
1128
+ const run = new AbortController();
1129
+ runRef.current = run;
1101
1130
  setState({
1102
1131
  ...initialState,
1103
1132
  phase: "processing",
1104
1133
  status: { title: "Processing...", details: "Validating and preparing files." }
1105
1134
  });
1106
1135
  try {
1107
- const outcome = await processFiles(newFiles, {
1108
- limits: await ship.getLimits(),
1136
+ const [files, limits] = await Promise.all([
1137
+ collect(),
1138
+ ship.getLimits({ signal: run.signal })
1139
+ ]);
1140
+ if (run.signal.aborted) return;
1141
+ if (files.length === 0) {
1142
+ setState({
1143
+ ...initialState,
1144
+ phase: "error",
1145
+ status: { title: "Empty Folder", details: "It has no files to deploy." }
1146
+ });
1147
+ return;
1148
+ }
1149
+ const outcome = await processFiles(files, {
1150
+ limits,
1151
+ // The pipeline says its status before its first wait, so a
1152
+ // cancelled run has none left to say.
1109
1153
  onStatus: (status) => setState((prev) => ({ ...prev, status }))
1110
1154
  });
1155
+ if (run.signal.aborted) return;
1111
1156
  setState({
1112
1157
  phase: outcome.phase,
1113
1158
  isDragging: false,
@@ -1116,15 +1161,33 @@ function useDrop({ ship }) {
1116
1161
  status: outcome.status,
1117
1162
  needsBuild: outcome.needsBuild
1118
1163
  });
1164
+ } catch (error) {
1165
+ if (run.signal.aborted) return;
1166
+ setState({
1167
+ ...initialState,
1168
+ phase: "error",
1169
+ status: {
1170
+ title: "Processing Failed",
1171
+ details: error instanceof Error ? error.message : String(error)
1172
+ }
1173
+ });
1119
1174
  } finally {
1120
- isProcessingRef.current = false;
1175
+ if (runRef.current === run) runRef.current = null;
1121
1176
  }
1122
1177
  },
1123
1178
  [ship]
1124
1179
  );
1180
+ const processFiles2 = useCallback(
1181
+ async (newFiles) => {
1182
+ if (!newFiles || newFiles.length === 0) return;
1183
+ await prepare(async () => newFiles);
1184
+ },
1185
+ [prepare]
1186
+ );
1125
1187
  const reset = useCallback(() => {
1188
+ runRef.current?.abort();
1189
+ runRef.current = null;
1126
1190
  setState(initialState);
1127
- isProcessingRef.current = false;
1128
1191
  }, []);
1129
1192
  const handleDragOver = useCallback((e) => {
1130
1193
  e.preventDefault();
@@ -1159,13 +1222,13 @@ function useDrop({ ship }) {
1159
1222
  if (file) files.push(file);
1160
1223
  }
1161
1224
  }
1162
- await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1163
- if (files.length === 0 && e.dataTransfer.files.length > 0) {
1164
- files.push(...Array.from(e.dataTransfer.files));
1165
- }
1166
- if (files.length > 0) await processFiles2(files);
1225
+ if (directories.length === 0 && files.length === 0) return;
1226
+ await prepare(async () => {
1227
+ await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1228
+ return files;
1229
+ });
1167
1230
  },
1168
- [processFiles2]
1231
+ [prepare]
1169
1232
  );
1170
1233
  const handleInputChange = useCallback(
1171
1234
  (e) => {