@cedarjs/internal 8.0.0-canary.3536 → 8.0.0-canary.3539

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.
@@ -30,6 +30,13 @@ export interface GqlormBackendConfig {
30
30
  membershipUserField: string;
31
31
  membershipOrganizationField: string;
32
32
  membershipModelExists: boolean;
33
+ /**
34
+ * Whether `cedar setup tenancy` replaced `@requireAuth` with
35
+ * `@requireOrgAuth` and `@requireUserAuth`. Fields then use
36
+ * `@requireUserAuth`, which checks what `@requireAuth` did: gqlorm does
37
+ * its own scoping to the user's organizations.
38
+ */
39
+ tenancyAuthDirectives?: boolean;
33
40
  }
34
41
  /**
35
42
  * Map a DMMF field type to its GraphQL SDL equivalent.
@@ -1 +1 @@
1
- {"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AA8BzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE3C,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAMD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;IACb,eAAe,EAAE,OAAO,CAAA;IACxB,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;I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,CAAC,QAAQ,GAClB,iBAAiB,EAAE,CAiDrB;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,iBAAiB,EAAE,GAC1B,MAAM,CA2CR;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAkDjE;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,EAAE,CA6D7E;AAkBD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CA6BvE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,EAAE,EAC1B,MAAM,GAAE,mBAAmD,GAC1D,MAAM,CAmsBR;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC;IACvD,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAC,CAqID"}
@@ -477,6 +477,7 @@ function generateGqlormBackendContent(models, config = DEFAULT_GQLORM_BACKEND_CO
477
477
  lines.push(" }");
478
478
  lines.push("");
479
479
  }
480
+ const requireAuthDirective = config.tenancyAuthDirectives ? "@requireUserAuth" : "@requireAuth";
480
481
  lines.push(" type Query {");
481
482
  for (const model of models) {
482
483
  const hasUserField = model.fields.some(
@@ -487,7 +488,7 @@ function generateGqlormBackendContent(models, config = DEFAULT_GQLORM_BACKEND_CO
487
488
  );
488
489
  const isMembershipModel = model.camelName === config.membershipModelCamel;
489
490
  const needsAuth = hasUserField || hasOrgField && config.membershipModelExists && !isMembershipModel;
490
- const authDirective = needsAuth ? "@requireAuth" : "@skipAuth";
491
+ const authDirective = needsAuth ? requireAuthDirective : "@skipAuth";
491
492
  lines.push(
492
493
  ` ${model.pluralName}: [${model.modelName}!]! ${authDirective}`
493
494
  );
@@ -511,7 +512,7 @@ function generateGqlormBackendContent(models, config = DEFAULT_GQLORM_BACKEND_CO
511
512
  );
512
513
  const isMembershipModel = model.camelName === config.membershipModelCamel;
513
514
  const needsAuth = hasUserField || hasOrgField && config.membershipModelExists && !isMembershipModel;
514
- const authDirective = needsAuth ? "@requireAuth" : "@skipAuth";
515
+ const authDirective = needsAuth ? requireAuthDirective : "@skipAuth";
515
516
  const idNullMark = model.idField.isRequired ? "!" : "";
516
517
  lines.push(
517
518
  ` create${model.modelName}(input: Create${model.modelName}Input!): ${model.modelName}! ${authDirective}`
@@ -974,7 +975,10 @@ async function generateGqlormArtifacts() {
974
975
  membershipModelCamel,
975
976
  membershipUserField,
976
977
  membershipOrganizationField,
977
- membershipModelExists
978
+ membershipModelExists,
979
+ tenancyAuthDirectives: fs.existsSync(
980
+ path.join(getPaths().api.directives, "requireOrgAuth")
981
+ )
978
982
  };
979
983
  const gqlormModels = allModels.filter(
980
984
  (m) => !existingTypes.has(m.modelName)
@@ -0,0 +1,11 @@
1
+ import '@cedarjs/auth'
2
+
3
+ // This app has tenancy, so every role check says which kind it is:
4
+ // useAuth().hasUserRole for currentUser.roles, and
5
+ // useCurrentOrg().hasOrgRole or OrgScope's roles for the role in the
6
+ // organization. No useAuth().hasRole or <PrivateSet roles>.
7
+ declare module '@cedarjs/auth' {
8
+ interface AuthTenancy {
9
+ enabled: true
10
+ }
11
+ }
@@ -25,6 +25,13 @@ export declare const generateTypeDefGqlorm: () => string[];
25
25
  * otherwise, and a stale file goes.
26
26
  */
27
27
  export declare const generateTypeDefRealtime: () => string[];
28
+ /**
29
+ * Marks `@cedarjs/auth`'s `AuthTenancy` as enabled when the web side depends
30
+ * on `@cedarjs/tenancy` (`cedar setup tenancy` adds it), which takes
31
+ * `useAuth().hasRole` and `<PrivateSet roles>` away from the app's types.
32
+ * None otherwise, and a stale file goes.
33
+ */
34
+ export declare const generateTypeDefTenancy: () => string[];
28
35
  export declare const generateTypeDefScenarios: () => string[];
29
36
  export declare const generateTypeDefTestMocks: () => string[];
30
37
  export declare const generateTypeDefGlobImports: () => string[];
@@ -1 +1 @@
1
- {"version":3,"file":"typeDefinitions.d.ts","sourceRoot":"","sources":["../../src/generate/typeDefinitions.ts"],"names":[],"mappings":"AA8CA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;EA2B5B,CAAA;AAED,eAAO,MAAM,mCAAmC,gBAK/C,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,aASvB,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,WAoDvB,CAAA;AAED,eAAO,MAAM,mBAAmB,gBAG/B,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,GAAG,MAAM,EAAE,mDAAsB,aAQlE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,MAAM,EAAE,mDAAsB,WAmHnE,CAAA;AAiBD,eAAO,MAAM,2BAA2B,gBAmEvC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBA8CtC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,qBAAqB,gBAEjC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,gBA8BnC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAEpC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAKpC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,4BAA4B,gBAExC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,gBAW5C,CAAA"}
1
+ {"version":3,"file":"typeDefinitions.d.ts","sourceRoot":"","sources":["../../src/generate/typeDefinitions.ts"],"names":[],"mappings":"AA8CA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;EA4B5B,CAAA;AAED,eAAO,MAAM,mCAAmC,gBAK/C,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,aASvB,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,GAAG,MAAM,EACT,mDAAsB,WAoDvB,CAAA;AAED,eAAO,MAAM,mBAAmB,gBAG/B,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,GAAG,MAAM,EAAE,mDAAsB,aAQlE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,MAAM,EAAE,mDAAsB,WAmHnE,CAAA;AAiBD,eAAO,MAAM,2BAA2B,gBAmEvC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBA8CtC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,qBAAqB,gBAEjC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,gBA8BnC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,gBA8BlC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAEpC,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAKpC,CAAA;AAED,eAAO,MAAM,0BAA0B,gBAEtC,CAAA;AAED,eAAO,MAAM,4BAA4B,gBAExC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,gBAW5C,CAAA"}
@@ -32,6 +32,7 @@ const generateTypeDefs = async () => {
32
32
  ...generateTypeDefCurrentUser(),
33
33
  ...generateTypeDefGqlorm(),
34
34
  ...generateTypeDefRealtime(),
35
+ ...generateTypeDefTenancy(),
35
36
  ...generateTypeDefRouterRoutes(),
36
37
  ...generateTypeDefGlobImports(),
37
38
  ...generateTypeDefGlobalContext(),
@@ -328,6 +329,27 @@ const generateTypeDefRealtime = () => {
328
329
  }
329
330
  return writeTypeDefIncludeFile("api-realtime.d.ts.template");
330
331
  };
332
+ const generateTypeDefTenancy = () => {
333
+ const paths = getPaths();
334
+ const typeDefPath = path.join(
335
+ paths.generated.types.includes,
336
+ "web-tenancy.d.ts"
337
+ );
338
+ let packageJson;
339
+ try {
340
+ packageJson = JSON.parse(
341
+ fs.readFileSync(path.join(paths.web.base, "package.json"), "utf-8")
342
+ );
343
+ } catch {
344
+ fs.rmSync(typeDefPath, { force: true });
345
+ return [];
346
+ }
347
+ if (!packageJson.dependencies?.["@cedarjs/tenancy"] && !packageJson.devDependencies?.["@cedarjs/tenancy"]) {
348
+ fs.rmSync(typeDefPath, { force: true });
349
+ return [];
350
+ }
351
+ return writeTypeDefIncludeFile("web-tenancy.d.ts.template");
352
+ };
331
353
  const generateTypeDefScenarios = () => {
332
354
  return writeTypeDefIncludeFile("api-scenarios.d.ts.template");
333
355
  };
@@ -397,6 +419,7 @@ export {
397
419
  generateTypeDefRouterPages,
398
420
  generateTypeDefRouterRoutes,
399
421
  generateTypeDefScenarios,
422
+ generateTypeDefTenancy,
400
423
  generateTypeDefTestMocks,
401
424
  generateTypeDefs,
402
425
  generateViteClientTypesDirective,
@@ -1 +1 @@
1
- {"version":3,"file":"validateSchema.d.ts","sourceRoot":"","sources":["../src/validateSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAA4B,MAAM,SAAS,CAAA;AAQrE,eAAO,MAAM,gCAAgC,0EAC4B,CAAA;AAEzE,eAAO,MAAM,0CAA0C,gFACwB,CAAA;AAE/E;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,UAS1B,CAAA;AAED,wBAAgB,cAAc,CAC5B,kBAAkB,EAAE,YAAY,EAChC,YAAY,GAAE,MAAM,EAA0B,QAwI/C;AAED,eAAO,MAAM,mBAAmB,qBAkC/B,CAAA"}
1
+ {"version":3,"file":"validateSchema.d.ts","sourceRoot":"","sources":["../src/validateSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAA4B,MAAM,SAAS,CAAA;AAQrE,eAAO,MAAM,gCAAgC,0EAC4B,CAAA;AAEzE,eAAO,MAAM,0CAA0C,gFACwB,CAAA;AAQ/E;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,UAS1B,CAAA;AAED,wBAAgB,cAAc,CAC5B,kBAAkB,EAAE,YAAY,EAChC,YAAY,GAAE,MAAM,EAA0B,QAwI/C;AAED,eAAO,MAAM,mBAAmB,qBAkC/B,CAAA"}
@@ -7,6 +7,7 @@ import { getPaths } from "@cedarjs/project-config";
7
7
  import { isServerFileSetup, isRealtimeSetup } from "./project.js";
8
8
  const DIRECTIVE_REQUIRED_ERROR_MESSAGE = "You must specify one of @requireAuth, @skipAuth or a custom directive";
9
9
  const DIRECTIVE_INVALID_ROLE_TYPES_ERROR_MESSAGE = "Please check that the requireAuth roles is a string or an array of strings.";
10
+ const ROLES_DIRECTIVES = ["requireAuth", "requireOrgAuth", "requireUserAuth"];
10
11
  const RESERVED_TYPES = [
11
12
  "Int",
12
13
  "Float",
@@ -62,7 +63,7 @@ function validateSchema(schemaDocumentNode, typesToCheck = ["Query", "Mutation"]
62
63
  validationOutput.push(`${fieldName} ${fieldTypeName}`);
63
64
  }
64
65
  field.directives?.forEach((directive) => {
65
- if (directive.name.value === "requireAuth") {
66
+ if (ROLES_DIRECTIVES.includes(directive.name.value)) {
66
67
  directive.arguments?.forEach((arg) => {
67
68
  if (arg.name.value === "roles") {
68
69
  if (arg.value.kind !== Kind.STRING && arg.value.kind !== Kind.LIST) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/internal",
3
- "version": "8.0.0-canary.3536",
3
+ "version": "8.0.0-canary.3539",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -118,16 +118,16 @@
118
118
  },
119
119
  "dependencies": {
120
120
  "@babel/core": "^7.26.10",
121
- "@babel/parser": "7.29.9",
121
+ "@babel/parser": "7.29.11",
122
122
  "@babel/traverse": "7.29.10",
123
- "@cedarjs/api": "8.0.0-canary.3536",
124
- "@cedarjs/babel-config": "8.0.0-canary.3536",
125
- "@cedarjs/cli-helpers": "8.0.0-canary.3536",
126
- "@cedarjs/graphql-server": "8.0.0-canary.3536",
127
- "@cedarjs/project-config": "8.0.0-canary.3536",
128
- "@cedarjs/router": "8.0.0-canary.3536",
129
- "@cedarjs/structure": "8.0.0-canary.3536",
130
- "@cedarjs/utils": "8.0.0-canary.3536",
123
+ "@cedarjs/api": "8.0.0-canary.3539",
124
+ "@cedarjs/babel-config": "8.0.0-canary.3539",
125
+ "@cedarjs/cli-helpers": "8.0.0-canary.3539",
126
+ "@cedarjs/graphql-server": "8.0.0-canary.3539",
127
+ "@cedarjs/project-config": "8.0.0-canary.3539",
128
+ "@cedarjs/router": "8.0.0-canary.3539",
129
+ "@cedarjs/structure": "8.0.0-canary.3539",
130
+ "@cedarjs/utils": "8.0.0-canary.3539",
131
131
  "@graphql-codegen/add": "6.0.1",
132
132
  "@graphql-codegen/cli": "6.3.1",
133
133
  "@graphql-codegen/client-preset": "5.3.0",
@@ -165,7 +165,7 @@
165
165
  "vite-tsconfig-paths": "6.1.1"
166
166
  },
167
167
  "devDependencies": {
168
- "@cedarjs/framework-tools": "8.0.0-canary.3536",
168
+ "@cedarjs/framework-tools": "8.0.0-canary.3539",
169
169
  "@jridgewell/trace-mapping": "0.3.31",
170
170
  "@oxc-project/types": "^0.155.0",
171
171
  "concurrently": "9.2.5",