MCPcopy Create free account
hub / github.com/hashintel/hash / seedCrmData

Function seedCrmData

apps/hash-api/src/seed-data/seed-crm-data.ts:393–1999  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

391/* -------------------------------------------------------------------------- */
392
393const seedCrmData = async () => {
394 const graphApi = createGraphClient(logger, {
395 host: getRequiredEnv("HASH_GRAPH_HTTP_HOST"),
396 port: Number.parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10),
397 });
398
399 const context = { graphApi, provenance };
400
401 const hashBotActorId = await getMachineIdByIdentifier(
402 context,
403 { actorId: publicUserAccountId },
404 { identifier: "h" },
405 ).then((maybeMachineId) => {
406 if (!maybeMachineId) {
407 throw new Error("Failed to get hash bot");
408 }
409 return maybeMachineId;
410 });
411
412 const authentication = { actorId: hashBotActorId };
413
414 let org = await getOrgByShortname(context, authentication, {
415 shortname: webShortname,
416 });
417 if (!org) {
418 org = await createOrg(context, authentication, {
419 shortname: webShortname,
420 name: "HASH",
421 });
422 }
423 const webId = org.webId;
424
425 /*
426 * Types are created (above, by the `@h` machine actor) in the `@h` web, where
427 * they are globally readable. The *entities*, however, are created in the
428 * existing `example-org` web and owned by it, so that all members of that org
429 * (the seeded `alice`, `bob01` and `instance-admin` users) can see them.
430 *
431 * We act as the org owner (`alice`) with a user-actor context, mirroring how
432 * `seedOrgsAndUsers` seeds pages into the org web. Org membership confers view
433 * access on web-owned entities, so no per-entity policies are required.
434 */
435 const orgOwner = await getUser(context, authentication, {
436 shortname: "alice",
437 });
438 if (!orgOwner) {
439 throw new Error(
440 'Seeded user "alice" not found — run the dev environment (which seeds users and the example org) before seeding CRM data.',
441 );
442 }
443
444 const exampleOrg = await getOrgByShortname(context, authentication, {
445 shortname: "example-org",
446 });
447 if (!exampleOrg) {
448 throw new Error(
449 'Org "example-org" not found — run the dev environment (which seeds users and the example org) before seeding CRM data.',
450 );

Callers 1

seed-crm-data.tsFile · 0.85

Calls 15

createGraphClientFunction · 0.90
getRequiredEnvFunction · 0.90
getMachineIdByIdentifierFunction · 0.90
getOrgByShortnameFunction · 0.90
createOrgFunction · 0.90
getUserFunction · 0.90
typedFunction · 0.85
boolFunction · 0.85
makeLinkTypeFunction · 0.85
batchMapFunction · 0.85
makeEntityFunction · 0.85
personValuePropsFunction · 0.85

Tested by

no test coverage detected