-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into flav/viz-draft
- Loading branch information
Showing
41 changed files
with
568 additions
and
816 deletions.
There are no files selected for viewing
60 changes: 30 additions & 30 deletions
60
connectors/migrations/20230606_deprecate_nango_connection_id.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { Op } from "sequelize"; | ||
|
||
import { sequelizeConnection } from "@connectors/resources/storage"; | ||
import { ConnectorModel } from "@connectors/resources/storage/models/connector_model"; | ||
|
||
async function main() { | ||
await ConnectorModel.update( | ||
{ | ||
connectionId: sequelizeConnection.col("nangoConnectionId"), | ||
}, | ||
{ | ||
// @ts-expect-error `connectionId` has been made non-nullable | ||
where: { | ||
connectionId: { | ||
[Op.eq]: null, | ||
}, | ||
}, | ||
} | ||
); | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.log("Done"); | ||
process.exit(0); | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
// import { Op } from "sequelize"; | ||
// | ||
// import { sequelizeConnection } from "@connectors/resources/storage"; | ||
// import { ConnectorModel } from "@connectors/resources/storage/models/connector_model"; | ||
// | ||
// async function main() { | ||
// await ConnectorModel.update( | ||
// { | ||
// connectionId: sequelizeConnection.col("nangoConnectionId"), | ||
// }, | ||
// { | ||
// // @ts-expect-error `connectionId` has been made non-nullable | ||
// where: { | ||
// connectionId: { | ||
// [Op.eq]: null, | ||
// }, | ||
// }, | ||
// } | ||
// ); | ||
// } | ||
// | ||
// main() | ||
// .then(() => { | ||
// console.log("Done"); | ||
// process.exit(0); | ||
// }) | ||
// .catch((e) => { | ||
// console.error(e); | ||
// process.exit(1); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { MicrosoftNodeType } from "./types"; | ||
import { isValidNodeType } from "./types"; | ||
|
||
export function internalIdFromTypeAndPath({ | ||
nodeType, | ||
itemAPIPath, | ||
}: { | ||
nodeType: MicrosoftNodeType; | ||
itemAPIPath: string; | ||
}): string { | ||
let stringId = ""; | ||
if (nodeType === "sites-root" || nodeType === "teams-root") { | ||
stringId = nodeType; | ||
} else { | ||
stringId = `${nodeType}/${itemAPIPath}`; | ||
} | ||
// encode to base64url so the internal id is URL-friendly | ||
return "microsoft-" + Buffer.from(stringId).toString("base64url"); | ||
} | ||
|
||
export function typeAndPathFromInternalId(internalId: string): { | ||
nodeType: MicrosoftNodeType; | ||
itemAPIPath: string; | ||
} { | ||
if (!internalId.startsWith("microsoft-")) { | ||
throw new Error(`Invalid internal id: ${internalId}`); | ||
} | ||
|
||
// decode from base64url | ||
const decodedId = Buffer.from( | ||
internalId.slice("microsoft-".length), | ||
"base64url" | ||
).toString(); | ||
|
||
if (decodedId === "sites-root" || decodedId === "teams-root") { | ||
return { nodeType: decodedId, itemAPIPath: "" }; | ||
} | ||
|
||
const [nodeType, ...resourcePathArr] = decodedId.split("/"); | ||
if (!nodeType || !isValidNodeType(nodeType)) { | ||
throw new Error( | ||
`Invalid internal id: ${decodedId} with nodeType: ${nodeType}` | ||
); | ||
} | ||
|
||
return { nodeType, itemAPIPath: resourcePathArr.join("/") }; | ||
} | ||
|
||
export function getDriveInternalIdFromItemId(itemId: string) { | ||
const { itemAPIPath } = typeAndPathFromInternalId(itemId); | ||
if (!itemAPIPath.startsWith("/drives/")) { | ||
throw new Error("Unexpected: no drive id for item"); | ||
} | ||
const parts = itemAPIPath.split("/"); | ||
return internalIdFromTypeAndPath({ | ||
nodeType: "drive", | ||
itemAPIPath: `/drives/${parts[2]}`, | ||
}); | ||
} |
Oops, something went wrong.