@payloadcms/plugin-multi-tenant 0.0.1

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.
Files changed (88) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +204 -0
  3. package/dist/components/GlobalViewRedirect/index.d.ts +10 -0
  4. package/dist/components/GlobalViewRedirect/index.d.ts.map +1 -0
  5. package/dist/components/GlobalViewRedirect/index.js +18 -0
  6. package/dist/components/GlobalViewRedirect/index.js.map +1 -0
  7. package/dist/components/TenantField/index.client.d.ts +10 -0
  8. package/dist/components/TenantField/index.client.d.ts.map +1 -0
  9. package/dist/components/TenantField/index.client.js +34 -0
  10. package/dist/components/TenantField/index.client.js.map +1 -0
  11. package/dist/components/TenantField/index.d.ts +3 -0
  12. package/dist/components/TenantField/index.d.ts.map +1 -0
  13. package/dist/components/TenantField/index.js +33 -0
  14. package/dist/components/TenantField/index.js.map +1 -0
  15. package/dist/components/TenantSelector/index.client.d.ts +11 -0
  16. package/dist/components/TenantSelector/index.client.d.ts.map +1 -0
  17. package/dist/components/TenantSelector/index.client.js +61 -0
  18. package/dist/components/TenantSelector/index.client.js.map +1 -0
  19. package/dist/components/TenantSelector/index.d.ts +10 -0
  20. package/dist/components/TenantSelector/index.d.ts.map +1 -0
  21. package/dist/components/TenantSelector/index.js +31 -0
  22. package/dist/components/TenantSelector/index.js.map +1 -0
  23. package/dist/components/TenantSelector/index.scss +4 -0
  24. package/dist/exports/rsc.d.ts +4 -0
  25. package/dist/exports/rsc.d.ts.map +1 -0
  26. package/dist/exports/rsc.js +5 -0
  27. package/dist/exports/rsc.js.map +1 -0
  28. package/dist/exports/types.d.ts +2 -0
  29. package/dist/exports/types.d.ts.map +1 -0
  30. package/dist/exports/types.js +3 -0
  31. package/dist/exports/types.js.map +1 -0
  32. package/dist/exports/utilities.d.ts +6 -0
  33. package/dist/exports/utilities.d.ts.map +1 -0
  34. package/dist/exports/utilities.js +7 -0
  35. package/dist/exports/utilities.js.map +1 -0
  36. package/dist/fields/tenantField/index.d.ts +12 -0
  37. package/dist/fields/tenantField/index.d.ts.map +1 -0
  38. package/dist/fields/tenantField/index.js +38 -0
  39. package/dist/fields/tenantField/index.js.map +1 -0
  40. package/dist/fields/userTenantsArrayField/index.d.ts +4 -0
  41. package/dist/fields/userTenantsArrayField/index.d.ts.map +1 -0
  42. package/dist/fields/userTenantsArrayField/index.js +20 -0
  43. package/dist/fields/userTenantsArrayField/index.js.map +1 -0
  44. package/dist/index.d.ts +4 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +112 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/types.d.ts +80 -0
  49. package/dist/types.d.ts.map +1 -0
  50. package/dist/types.js +3 -0
  51. package/dist/types.js.map +1 -0
  52. package/dist/utilities/combineWhereConstraints.d.ts +3 -0
  53. package/dist/utilities/combineWhereConstraints.d.ts.map +1 -0
  54. package/dist/utilities/combineWhereConstraints.js +19 -0
  55. package/dist/utilities/combineWhereConstraints.js.map +1 -0
  56. package/dist/utilities/extractID.d.ts +3 -0
  57. package/dist/utilities/extractID.d.ts.map +1 -0
  58. package/dist/utilities/extractID.js +8 -0
  59. package/dist/utilities/extractID.js.map +1 -0
  60. package/dist/utilities/getGlobalViewRedirect.d.ts +10 -0
  61. package/dist/utilities/getGlobalViewRedirect.d.ts.map +1 -0
  62. package/dist/utilities/getGlobalViewRedirect.js +44 -0
  63. package/dist/utilities/getGlobalViewRedirect.js.map +1 -0
  64. package/dist/utilities/getTenantAccess.d.ts +5 -0
  65. package/dist/utilities/getTenantAccess.d.ts.map +1 -0
  66. package/dist/utilities/getTenantAccess.js +14 -0
  67. package/dist/utilities/getTenantAccess.js.map +1 -0
  68. package/dist/utilities/getTenantFromCookie.d.ts +2 -0
  69. package/dist/utilities/getTenantFromCookie.d.ts.map +1 -0
  70. package/dist/utilities/getTenantFromCookie.js +8 -0
  71. package/dist/utilities/getTenantFromCookie.js.map +1 -0
  72. package/dist/utilities/getTenantListFilter.d.ts +8 -0
  73. package/dist/utilities/getTenantListFilter.d.ts.map +1 -0
  74. package/dist/utilities/getTenantListFilter.js +15 -0
  75. package/dist/utilities/getTenantListFilter.js.map +1 -0
  76. package/dist/utilities/getUserTenantIDs.d.ts +9 -0
  77. package/dist/utilities/getUserTenantIDs.d.ts.map +1 -0
  78. package/dist/utilities/getUserTenantIDs.js +22 -0
  79. package/dist/utilities/getUserTenantIDs.js.map +1 -0
  80. package/dist/utilities/withTenantAccess.d.ts +9 -0
  81. package/dist/utilities/withTenantAccess.d.ts.map +1 -0
  82. package/dist/utilities/withTenantAccess.js +26 -0
  83. package/dist/utilities/withTenantAccess.js.map +1 -0
  84. package/dist/utilities/withTenantListFilter.d.ts +13 -0
  85. package/dist/utilities/withTenantListFilter.d.ts.map +1 -0
  86. package/dist/utilities/withTenantListFilter.js +36 -0
  87. package/dist/utilities/withTenantListFilter.js.map +1 -0
  88. package/package.json +79 -0
@@ -0,0 +1,36 @@
1
+ import { getTenantListFilter } from './getTenantListFilter.js';
2
+ /**
3
+ * Combines a base list filter with a tenant list filter
4
+ *
5
+ * Combines where constraints inside of an AND operator
6
+ */ export const withTenantListFilter = ({ baseListFilter, tenantFieldName })=>async (args)=>{
7
+ const filterConstraints = [];
8
+ if (typeof baseListFilter === 'function') {
9
+ const baseListFilterResult = await baseListFilter(args);
10
+ if (baseListFilterResult) {
11
+ filterConstraints.push(baseListFilterResult);
12
+ }
13
+ }
14
+ const tenantListFilter = getTenantListFilter({
15
+ req: args.req,
16
+ tenantFieldName
17
+ });
18
+ if (tenantListFilter) {
19
+ filterConstraints.push(tenantListFilter);
20
+ }
21
+ if (filterConstraints.length) {
22
+ const combinedWhere = {
23
+ and: []
24
+ };
25
+ filterConstraints.forEach((constraint)=>{
26
+ if (typeof constraint === 'object') {
27
+ combinedWhere.and.push(constraint);
28
+ }
29
+ });
30
+ return combinedWhere;
31
+ }
32
+ // Access control will take it from here
33
+ return null;
34
+ };
35
+
36
+ //# sourceMappingURL=withTenantListFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/withTenantListFilter.ts"],"sourcesContent":["import type { BaseListFilter, Where } from 'payload'\n\nimport { getTenantListFilter } from './getTenantListFilter.js'\n\ntype Args = {\n baseListFilter?: BaseListFilter\n tenantFieldName: string\n}\n/**\n * Combines a base list filter with a tenant list filter\n *\n * Combines where constraints inside of an AND operator\n */\nexport const withTenantListFilter =\n ({ baseListFilter, tenantFieldName }: Args): BaseListFilter =>\n async (args) => {\n const filterConstraints = []\n\n if (typeof baseListFilter === 'function') {\n const baseListFilterResult = await baseListFilter(args)\n\n if (baseListFilterResult) {\n filterConstraints.push(baseListFilterResult)\n }\n }\n\n const tenantListFilter = getTenantListFilter({\n req: args.req,\n tenantFieldName,\n })\n\n if (tenantListFilter) {\n filterConstraints.push(tenantListFilter)\n }\n\n if (filterConstraints.length) {\n const combinedWhere: Where = { and: [] }\n filterConstraints.forEach((constraint) => {\n if (typeof constraint === 'object') {\n combinedWhere.and.push(constraint)\n }\n })\n return combinedWhere\n }\n\n // Access control will take it from here\n return null\n }\n"],"names":["getTenantListFilter","withTenantListFilter","baseListFilter","tenantFieldName","args","filterConstraints","baseListFilterResult","push","tenantListFilter","req","length","combinedWhere","and","forEach","constraint"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,2BAA0B;AAM9D;;;;CAIC,GACD,OAAO,MAAMC,uBACX,CAAC,EAAEC,cAAc,EAAEC,eAAe,EAAQ,GAC1C,OAAOC;QACL,MAAMC,oBAAoB,EAAE;QAE5B,IAAI,OAAOH,mBAAmB,YAAY;YACxC,MAAMI,uBAAuB,MAAMJ,eAAeE;YAElD,IAAIE,sBAAsB;gBACxBD,kBAAkBE,IAAI,CAACD;YACzB;QACF;QAEA,MAAME,mBAAmBR,oBAAoB;YAC3CS,KAAKL,KAAKK,GAAG;YACbN;QACF;QAEA,IAAIK,kBAAkB;YACpBH,kBAAkBE,IAAI,CAACC;QACzB;QAEA,IAAIH,kBAAkBK,MAAM,EAAE;YAC5B,MAAMC,gBAAuB;gBAAEC,KAAK,EAAE;YAAC;YACvCP,kBAAkBQ,OAAO,CAAC,CAACC;gBACzB,IAAI,OAAOA,eAAe,UAAU;oBAClCH,cAAcC,GAAG,CAACL,IAAI,CAACO;gBACzB;YACF;YACA,OAAOH;QACT;QAEA,wCAAwC;QACxC,OAAO;IACT,EAAC"}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@payloadcms/plugin-multi-tenant",
3
+ "version": "0.0.1",
4
+ "description": "Multi Tenant plugin for Payload",
5
+ "keywords": [
6
+ "payload",
7
+ "cms",
8
+ "plugin",
9
+ "typescript",
10
+ "react",
11
+ "multi-tenant",
12
+ "nextjs"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/payloadcms/payload.git",
17
+ "directory": "packages/plugin-multi-tenant"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
21
+ "maintainers": [
22
+ {
23
+ "name": "Payload",
24
+ "email": "info@payloadcms.com",
25
+ "url": "https://payloadcms.com"
26
+ }
27
+ ],
28
+ "type": "module",
29
+ "exports": {
30
+ ".": {
31
+ "import": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./types": {
36
+ "import": "./dist/exports/types.js",
37
+ "types": "./dist/exports/types.d.ts",
38
+ "default": "./dist/exports/types.js"
39
+ },
40
+ "./rsc": {
41
+ "import": "./dist/exports/rsc.js",
42
+ "types": "./dist/exports/rsc.d.ts",
43
+ "default": "./dist/exports/rsc.js"
44
+ },
45
+ "./utilites": {
46
+ "import": "./dist/exports/utilites.js",
47
+ "types": "./dist/exports/utilites.d.ts",
48
+ "default": "./dist/exports/utilites.js"
49
+ }
50
+ },
51
+ "main": "./dist/index.js",
52
+ "types": "./dist/index.d.ts",
53
+ "files": [
54
+ "dist",
55
+ "types.js",
56
+ "types.d.ts"
57
+ ],
58
+ "devDependencies": {
59
+ "@payloadcms/ui": "3.15.1",
60
+ "payload": "3.15.1",
61
+ "@payloadcms/eslint-config": "3.9.0"
62
+ },
63
+ "peerDependencies": {
64
+ "next": "^15.0.3",
65
+ "@payloadcms/ui": "3.15.1",
66
+ "payload": "3.15.1"
67
+ },
68
+ "homepage:": "https://payloadcms.com",
69
+ "scripts": {
70
+ "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
71
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
72
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
73
+ "clean": "rimraf {dist,*.tsbuildinfo}",
74
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
75
+ "lint": "eslint .",
76
+ "lint:fix": "eslint . --fix",
77
+ "pack:plugin": "pnpm prepublishOnly && pnpm copyfiles && pnpm pack"
78
+ }
79
+ }