@infuro/cms-core 1.0.29 → 1.0.31

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 (58) hide show
  1. package/README.md +17 -13
  2. package/dist/admin.cjs +8522 -3281
  3. package/dist/admin.cjs.map +1 -1
  4. package/dist/admin.d.cts +13 -2
  5. package/dist/admin.d.ts +13 -2
  6. package/dist/admin.js +8210 -2957
  7. package/dist/admin.js.map +1 -1
  8. package/dist/api.cjs +5099 -1167
  9. package/dist/api.cjs.map +1 -1
  10. package/dist/api.d.cts +2 -2
  11. package/dist/api.d.ts +2 -2
  12. package/dist/api.js +4847 -909
  13. package/dist/api.js.map +1 -1
  14. package/dist/auth.cjs +461 -62
  15. package/dist/auth.cjs.map +1 -1
  16. package/dist/auth.d.cts +73 -47
  17. package/dist/auth.d.ts +73 -47
  18. package/dist/auth.js +425 -38
  19. package/dist/auth.js.map +1 -1
  20. package/dist/cli.cjs +21 -14
  21. package/dist/cli.cjs.map +1 -1
  22. package/dist/cli.js +21 -14
  23. package/dist/cli.js.map +1 -1
  24. package/dist/{index-D9SdaDJ0.d.ts → index-BcMRGNjS.d.cts} +36 -3
  25. package/dist/{index-BPQSXgXF.d.cts → index-Bda8D1Rm.d.ts} +36 -3
  26. package/dist/index.cjs +4753 -740
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +301 -36
  29. package/dist/index.d.ts +301 -36
  30. package/dist/index.js +4750 -768
  31. package/dist/index.js.map +1 -1
  32. package/dist/migrations/1775400000001-AddDiscountAndOrderAddresses.ts +274 -0
  33. package/dist/migrations/1775800000000-VendorsAndVendorUsers.ts +74 -0
  34. package/dist/migrations/1775900000000-StoreVendorIdColumns.ts +124 -0
  35. package/dist/migrations/1775910000000-VendorOwnerRbacSeed.ts +54 -0
  36. package/dist/migrations/1775920000000-VendorOwnerSettingsPermission.ts +25 -0
  37. package/dist/migrations/1775930000000-VendorGroupStorePermissions.ts +54 -0
  38. package/dist/migrations/1775940000000-VendorRls.ts +71 -0
  39. package/dist/migrations/1775950000000-VendorCustomers.ts +87 -0
  40. package/dist/migrations/1775950000001-VendorCustomersPermissions.ts +67 -0
  41. package/dist/migrations/1778652250860-CreateCurrencyTables.ts +16 -0
  42. package/dist/migrations/1778652250861-OrderAddressTables.ts +88 -0
  43. package/dist/migrations/1778652250862-UpdateDiscountandRules.ts +100 -0
  44. package/dist/migrations/1778652250863-MakeCouponCodeNullable.ts +19 -0
  45. package/dist/migrations/1778652250864-RemoveUniqueConstraintFromDiscountCouponCode.ts +22 -0
  46. package/dist/migrations/1778652250865-FixOrdersAddressForeignKeys.ts +71 -0
  47. package/dist/migrations/1778660000000-DiscountVendorId.ts +90 -0
  48. package/dist/migrations/1778660000001-FixOrdersAddressFkToOrderAddresses.ts +79 -0
  49. package/dist/migrations/1778660000002-VendorUserIdInviteStatus.ts +61 -0
  50. package/dist/theme.d.cts +2 -2
  51. package/dist/theme.d.ts +2 -2
  52. package/dist/{types-D34wmivy.d.cts → types-DCVaXlPV.d.cts} +1 -1
  53. package/dist/{types-D34wmivy.d.ts → types-DCVaXlPV.d.ts} +1 -1
  54. package/dist/vendor-scope-DTYhJk_I.d.cts +129 -0
  55. package/dist/vendor-scope-DTYhJk_I.d.ts +129 -0
  56. package/package.json +9 -2
  57. package/dist/helpers-dlrF_49e.d.cts +0 -60
  58. package/dist/helpers-dlrF_49e.d.ts +0 -60
package/README.md CHANGED
@@ -173,21 +173,22 @@ import { getServerSession } from 'next-auth';
173
173
  import { createCmsApiHandler } from '@infuro/cms-core/api';
174
174
  import { CMS_ENTITY_MAP } from '@infuro/cms-core';
175
175
  import { getDataSourceInitialized } from '@/lib/data-source';
176
- import {
177
- requireAuth,
178
- requireAdminAccess,
179
- requireEntityPermission,
180
- getAuthenticatedUser,
181
- } from '@/lib/auth-helpers';
176
+ import { createCmsAuthBundle } from '@infuro/cms-core/auth';
177
+ import { authOptions } from '@/lib/auth-options';
182
178
  import { getCms } from '@/lib/cms';
183
179
  import bcrypt from 'bcryptjs';
184
180
 
185
181
  const baseUrl = process.env.NEXTAUTH_URL || 'http://localhost:3000';
186
182
 
183
+ const auth = createCmsAuthBundle(
184
+ () => getServerSession(authOptions).then((s) => s ?? null),
185
+ NextResponse
186
+ );
187
+
187
188
  async function requireAdminApiAuth(req: Request) {
188
- const a = await requireAuth(req);
189
+ const a = await auth.requireAuth(req);
189
190
  if (a) return a;
190
- return requireAdminAccess(req);
191
+ return auth.requireAdminAccess(req);
191
192
  }
192
193
 
193
194
  let handlerPromise: Promise<ReturnType<typeof createCmsApiHandler>> | null = null;
@@ -200,8 +201,9 @@ async function getHandler() {
200
201
  dataSource,
201
202
  entityMap: CMS_ENTITY_MAP,
202
203
  requireAuth: requireAdminApiAuth,
203
- requireEntityPermission,
204
- getSessionUser: getAuthenticatedUser,
204
+ requireEntityPermission: auth.requireEntityPermission,
205
+ getSessionUser: auth.getSessionUser,
206
+ getAuthenticatedUser: auth.getAuthenticatedUser,
205
207
  json: NextResponse.json.bind(NextResponse),
206
208
  getCms,
207
209
  userAuth: {
@@ -286,11 +288,13 @@ async function getOptions() {
286
288
  const userRepo = dataSource.getRepository(CMS_ENTITY_MAP.users);
287
289
  return getNextAuthOptions({
288
290
  getUserByEmail: async (email: string) => {
289
- return userRepo.findOne({
291
+ const user = await userRepo.findOne({
290
292
  where: { email },
291
293
  relations: ['group', 'group.permissions'],
292
- select: ['id', 'email', 'name', 'password', 'blocked', 'deleted', 'groupId'],
293
- }) as any;
294
+ select: ['id', 'email', 'name', 'password', 'blocked', 'deleted', 'groupId', 'adminAccess'],
295
+ });
296
+ const { enrichUserWithVendorContext } = await import('@infuro/cms-core');
297
+ return enrichUserWithVendorContext(dataSource, user as any);
294
298
  },
295
299
  comparePassword: (plain, hash) => Promise.resolve(bcrypt.compareSync(plain, hash)),
296
300
  signInPage: '/admin/signin',