-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.ts
More file actions
56 lines (43 loc) · 1.81 KB
/
setup.ts
File metadata and controls
56 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node --strip-types
import assert from "node:assert";
import { connect, type ManagedCollection } from "framer-api";
import { config } from "../src/config";
if (process.loadEnvFile) {
process.loadEnvFile(".env");
}
const projectUrl = process.env.FRAMER_PROJECT_URL;
const apiKey = process.env.FRAMER_API_KEY;
const collectionName = process.env.FRAMER_COLLECTION_NAME;
assert(projectUrl, "FRAMER_PROJECT_URL required");
assert(apiKey, "FRAMER_API_KEY required");
assert(collectionName, "FRAMER_COLLECTION_NAME required");
using framer = await connect(projectUrl, apiKey);
async function findOrCreateCollection(name: string) {
const existingCollections = await framer.getManagedCollections();
const existing = existingCollections.find((c) => c.name === name);
if (existing) {
console.log(`Found existing collection [id: ${existing.id}]`);
return existing;
}
const collection = await framer.createManagedCollection(name);
console.log(`Created collection [id: ${collection.id}]`);
return collection;
}
async function setupFields(collection: ManagedCollection) {
const fields = config.FIELD_MAPPING.map((mapping) => ({
type: mapping.type,
name: mapping.framerName,
id: mapping.framerId,
}));
await collection.setFields(fields);
const setFields = await collection.getFields();
console.log(`Set ${setFields.length} fields`);
}
async function logCollectionStatus(collection: ManagedCollection) {
const itemIds = await collection.getItemIds();
console.log(`Collection ready [existing items: ${itemIds.length}]`);
}
const collection = await findOrCreateCollection(collectionName);
await setupFields(collection);
await logCollectionStatus(collection);
console.log("\n✅ Setup complete! Collection is ready for webhook integration.");