Update plugins

This commit is contained in:
Gregory Schier
2025-01-13 08:53:14 -08:00
parent d37cfad862
commit 40a77be556
3 changed files with 65 additions and 29 deletions

View File

@@ -7232,53 +7232,54 @@ function pluginHookImport(ctx, contents) {
folders: [] folders: []
}; };
const workspacesToImport = parsed.resources.filter(isWorkspace); const workspacesToImport = parsed.resources.filter(isWorkspace);
for (const workspaceToImport of workspacesToImport) { for (const w of workspacesToImport) {
resources.workspaces.push({ resources.workspaces.push({
id: convertId(workspaceToImport._id), id: convertId(w._id),
createdAt: new Date(workspacesToImport.created ?? Date.now()).toISOString().replace("Z", ""), createdAt: w.created ? new Date(w.created).toISOString().replace("Z", "") : void 0,
updatedAt: new Date(workspacesToImport.updated ?? Date.now()).toISOString().replace("Z", ""), updatedAt: w.updated ? new Date(w.updated).toISOString().replace("Z", "") : void 0,
model: "workspace", model: "workspace",
name: workspaceToImport.name, name: w.name,
description: workspacesToImport.description description: w.description || void 0
}); });
const environmentsToImport = parsed.resources.filter( const environmentsToImport = parsed.resources.filter(
(r) => isEnvironment(r) (r) => isEnvironment(r)
); );
resources.environments.push( resources.environments.push(
...environmentsToImport.map((r) => importEnvironment(r, workspaceToImport._id)) ...environmentsToImport.map((r) => importEnvironment(r, w._id))
); );
const nextFolder = (parentId) => { const nextFolder = (parentId) => {
const children = parsed.resources.filter((r) => r.parentId === parentId); const children = parsed.resources.filter((r) => r.parentId === parentId);
let sortPriority = 0; let sortPriority = 0;
for (const child of children) { for (const child of children) {
if (isRequestGroup(child)) { if (isRequestGroup(child)) {
resources.folders.push(importFolder(child, workspaceToImport._id)); resources.folders.push(importFolder(child, w._id));
nextFolder(child._id); nextFolder(child._id);
} else if (isHttpRequest(child)) { } else if (isHttpRequest(child)) {
resources.httpRequests.push( resources.httpRequests.push(
importHttpRequest(child, workspaceToImport._id, sortPriority++) importHttpRequest(child, w._id, sortPriority++)
); );
} else if (isGrpcRequest(child)) { } else if (isGrpcRequest(child)) {
resources.grpcRequests.push( resources.grpcRequests.push(
importGrpcRequest(child, workspaceToImport._id, sortPriority++) importGrpcRequest(child, w._id, sortPriority++)
); );
} }
} }
}; };
nextFolder(workspaceToImport._id); nextFolder(w._id);
} }
resources.httpRequests = resources.httpRequests.filter(Boolean); resources.httpRequests = resources.httpRequests.filter(Boolean);
resources.grpcRequests = resources.grpcRequests.filter(Boolean); resources.grpcRequests = resources.grpcRequests.filter(Boolean);
resources.environments = resources.environments.filter(Boolean); resources.environments = resources.environments.filter(Boolean);
resources.workspaces = resources.workspaces.filter(Boolean); resources.workspaces = resources.workspaces.filter(Boolean);
return { resources }; return { resources: deleteUndefinedAttrs(resources) };
} }
function importEnvironment(e, workspaceId) { function importEnvironment(e, workspaceId) {
return { return {
id: convertId(e._id), id: convertId(e._id),
createdAt: new Date(e.created ?? Date.now()).toISOString().replace("Z", ""), createdAt: e.created ? new Date(e.created).toISOString().replace("Z", "") : void 0,
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace("Z", ""), updatedAt: e.updated ? new Date(e.updated).toISOString().replace("Z", "") : void 0,
workspaceId: convertId(workspaceId), workspaceId: convertId(workspaceId),
environmentId: e.parentId === workspaceId ? null : convertId(e.parentId),
model: "environment", model: "environment",
name: e.name, name: e.name,
variables: Object.entries(e.data).map(([name, value]) => ({ variables: Object.entries(e.data).map(([name, value]) => ({
@@ -7291,11 +7292,11 @@ function importEnvironment(e, workspaceId) {
function importFolder(f, workspaceId) { function importFolder(f, workspaceId) {
return { return {
id: convertId(f._id), id: convertId(f._id),
createdAt: new Date(f.created ?? Date.now()).toISOString().replace("Z", ""), createdAt: f.created ? new Date(f.created).toISOString().replace("Z", "") : void 0,
updatedAt: new Date(f.updated ?? Date.now()).toISOString().replace("Z", ""), updatedAt: f.updated ? new Date(f.updated).toISOString().replace("Z", "") : void 0,
folderId: f.parentId === workspaceId ? null : convertId(f.parentId), folderId: f.parentId === workspaceId ? null : convertId(f.parentId),
workspaceId: convertId(workspaceId), workspaceId: convertId(workspaceId),
description: f.description ?? null, description: f.description || void 0,
model: "folder", model: "folder",
name: f.name name: f.name
}; };
@@ -7306,14 +7307,14 @@ function importGrpcRequest(r, workspaceId, sortPriority = 0) {
const method = parts[1] ?? null; const method = parts[1] ?? null;
return { return {
id: convertId(r._id), id: convertId(r._id),
createdAt: new Date(r.created ?? Date.now()).toISOString().replace("Z", ""), createdAt: r.created ? new Date(r.created).toISOString().replace("Z", "") : void 0,
updatedAt: new Date(r.updated ?? Date.now()).toISOString().replace("Z", ""), updatedAt: r.updated ? new Date(r.updated).toISOString().replace("Z", "") : void 0,
workspaceId: convertId(workspaceId), workspaceId: convertId(workspaceId),
folderId: r.parentId === workspaceId ? null : convertId(r.parentId), folderId: r.parentId === workspaceId ? null : convertId(r.parentId),
model: "grpc_request", model: "grpc_request",
sortPriority, sortPriority,
name: r.name, name: r.name,
description: r.description ?? null, description: r.description || void 0,
url: convertSyntax(r.url), url: convertSyntax(r.url),
service, service,
method, method,
@@ -7373,14 +7374,14 @@ function importHttpRequest(r, workspaceId, sortPriority = 0) {
} }
return { return {
id: convertId(r._id), id: convertId(r._id),
createdAt: new Date(r.created ?? Date.now()).toISOString().replace("Z", ""), createdAt: r.created ? new Date(r.created).toISOString().replace("Z", "") : void 0,
updatedAt: new Date(r.updated ?? Date.now()).toISOString().replace("Z", ""), updatedAt: r.updated ? new Date(r.updated).toISOString().replace("Z", "") : void 0,
workspaceId: convertId(workspaceId), workspaceId: convertId(workspaceId),
folderId: r.parentId === workspaceId ? null : convertId(r.parentId), folderId: r.parentId === workspaceId ? null : convertId(r.parentId),
model: "http_request", model: "http_request",
sortPriority, sortPriority,
name: r.name, name: r.name,
description: r.description ?? null, description: r.description || void 0,
url: convertSyntax(r.url), url: convertSyntax(r.url),
body, body,
bodyType, bodyType,
@@ -7425,6 +7426,17 @@ function convertId(id) {
} }
return `GENERATE_ID::${id}`; return `GENERATE_ID::${id}`;
} }
function deleteUndefinedAttrs(obj) {
if (Array.isArray(obj) && obj != null) {
return obj.map(deleteUndefinedAttrs);
} else if (typeof obj === "object" && obj != null) {
return Object.fromEntries(
Object.entries(obj).filter(([, v]) => v !== void 0).map(([k, v]) => [k, deleteUndefinedAttrs(v)])
);
} else {
return obj;
}
}
// Annotate the CommonJS export names for ESM import in node: // Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = { 0 && (module.exports = {
pluginHookImport pluginHookImport

View File

@@ -145878,7 +145878,7 @@ function pluginHookImport(_ctx, contents) {
model: "workspace", model: "workspace",
id: generateId("workspace"), id: generateId("workspace"),
name: info.name || "Postman Import", name: info.name || "Postman Import",
description: info.description?.content ?? info.description ?? "" description: info.description?.content ?? info.description
}; };
exportResources.workspaces.push(workspace); exportResources.workspaces.push(workspace);
const environment = { const environment = {
@@ -145931,7 +145931,7 @@ function pluginHookImport(_ctx, contents) {
workspaceId: workspace.id, workspaceId: workspace.id,
folderId, folderId,
name: v.name, name: v.name,
description: v.description, description: v.description || void 0,
method: r.method || "GET", method: r.method || "GET",
url, url,
urlParameters, urlParameters,
@@ -145949,7 +145949,8 @@ function pluginHookImport(_ctx, contents) {
for (const item of root.item) { for (const item of root.item) {
importItem(item); importItem(item);
} }
return { resources: convertTemplateSyntax(exportResources) }; const resources = deleteUndefinedAttrs(convertTemplateSyntax(exportResources));
return { resources };
} }
function convertUrl(url) { function convertUrl(url) {
if (typeof url === "string") { if (typeof url === "string") {
@@ -146131,6 +146132,17 @@ function convertTemplateSyntax(obj) {
return obj; return obj;
} }
} }
function deleteUndefinedAttrs(obj) {
if (Array.isArray(obj) && obj != null) {
return obj.map(deleteUndefinedAttrs);
} else if (typeof obj === "object" && obj != null) {
return Object.fromEntries(
Object.entries(obj).filter(([, v]) => v !== void 0).map(([k, v]) => [k, deleteUndefinedAttrs(v)])
);
} else {
return obj;
}
}
var idCount = {}; var idCount = {};
function generateId(model) { function generateId(model) {
idCount[model] = (idCount[model] ?? -1) + 1; idCount[model] = (idCount[model] ?? -1) + 1;

View File

@@ -45,7 +45,7 @@ function pluginHookImport(_ctx, contents) {
model: "workspace", model: "workspace",
id: generateId("workspace"), id: generateId("workspace"),
name: info.name || "Postman Import", name: info.name || "Postman Import",
description: info.description?.content ?? info.description ?? "" description: info.description?.content ?? info.description
}; };
exportResources.workspaces.push(workspace); exportResources.workspaces.push(workspace);
const environment = { const environment = {
@@ -98,7 +98,7 @@ function pluginHookImport(_ctx, contents) {
workspaceId: workspace.id, workspaceId: workspace.id,
folderId, folderId,
name: v.name, name: v.name,
description: v.description, description: v.description || void 0,
method: r.method || "GET", method: r.method || "GET",
url, url,
urlParameters, urlParameters,
@@ -116,7 +116,8 @@ function pluginHookImport(_ctx, contents) {
for (const item of root.item) { for (const item of root.item) {
importItem(item); importItem(item);
} }
return { resources: convertTemplateSyntax(exportResources) }; const resources = deleteUndefinedAttrs(convertTemplateSyntax(exportResources));
return { resources };
} }
function convertUrl(url) { function convertUrl(url) {
if (typeof url === "string") { if (typeof url === "string") {
@@ -298,6 +299,17 @@ function convertTemplateSyntax(obj) {
return obj; return obj;
} }
} }
function deleteUndefinedAttrs(obj) {
if (Array.isArray(obj) && obj != null) {
return obj.map(deleteUndefinedAttrs);
} else if (typeof obj === "object" && obj != null) {
return Object.fromEntries(
Object.entries(obj).filter(([, v]) => v !== void 0).map(([k, v]) => [k, deleteUndefinedAttrs(v)])
);
} else {
return obj;
}
}
var idCount = {}; var idCount = {};
function generateId(model) { function generateId(model) {
idCount[model] = (idCount[model] ?? -1) + 1; idCount[model] = (idCount[model] ?? -1) + 1;