@sqrzro/addon-admins 4.0.0-alpha.3 → 4.0.0-alpha.6

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 (37) hide show
  1. package/dist/DEPRECATED_addon/config.d.ts +6 -0
  2. package/dist/DEPRECATED_addon/config.d.ts.map +1 -0
  3. package/dist/DEPRECATED_addon/config.js +11 -0
  4. package/dist/DEPRECATED_addon/defaults.d.ts +4 -0
  5. package/dist/DEPRECATED_addon/defaults.d.ts.map +1 -0
  6. package/dist/DEPRECATED_addon/defaults.js +6 -0
  7. package/dist/DEPRECATED_addon/index.d.ts +6 -0
  8. package/dist/DEPRECATED_addon/index.d.ts.map +1 -0
  9. package/dist/DEPRECATED_addon/index.js +9 -0
  10. package/dist/DEPRECATED_addon/interfaces.d.ts +9 -0
  11. package/dist/DEPRECATED_addon/interfaces.d.ts.map +1 -0
  12. package/dist/DEPRECATED_addon/interfaces.js +1 -0
  13. package/dist/addon/config.d.ts +2 -1
  14. package/dist/addon/config.d.ts.map +1 -1
  15. package/dist/addon/config.js +6 -6
  16. package/dist/addon/defaults.d.ts +4 -0
  17. package/dist/addon/defaults.d.ts.map +1 -0
  18. package/dist/addon/defaults.js +6 -0
  19. package/dist/addon/index.d.ts +2 -2
  20. package/dist/addon/index.d.ts.map +1 -1
  21. package/dist/addon/index.js +4 -4
  22. package/dist/addon/interfaces.d.ts +2 -0
  23. package/dist/addon/interfaces.d.ts.map +1 -1
  24. package/dist/config/index.d.ts +7 -0
  25. package/dist/config/index.d.ts.map +1 -0
  26. package/dist/config/index.js +10 -0
  27. package/dist/repositories/AdminRepository.d.ts.map +1 -1
  28. package/dist/repositories/AdminRepository.js +13 -20
  29. package/dist/repositories/index.d.ts +114 -0
  30. package/dist/repositories/index.d.ts.map +1 -0
  31. package/dist/repositories/index.js +63 -0
  32. package/dist/repository/index.d.ts +119 -0
  33. package/dist/repository/index.d.ts.map +1 -0
  34. package/dist/repository/index.js +76 -0
  35. package/dist/rules/id.d.ts.map +1 -1
  36. package/dist/rules/id.js +1 -1
  37. package/package.json +10 -15
@@ -0,0 +1,6 @@
1
+ import { AppConfig } from '@sqrzro/config';
2
+ import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
3
+ import type { AdminsAddonConfigObject, BaseAdminsAddonConfigObject } from './interfaces';
4
+ export declare function setConfig(db: NodePgDatabase, appConfig: AppConfig, cfg?: Partial<BaseAdminsAddonConfigObject>): void;
5
+ export declare function getConfig(): AdminsAddonConfigObject;
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/DEPRECATED_addon/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAIzF,wBAAgB,SAAS,CACrB,EAAE,EAAE,cAAc,EAClB,SAAS,EAAE,SAAS,EACpB,GAAG,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAC3C,IAAI,CAEN;AAED,wBAAgB,SAAS,IAAI,uBAAuB,CAKnD"}
@@ -0,0 +1,11 @@
1
+ import applyDefaults from './defaults';
2
+ let config = null;
3
+ export function setConfig(db, appConfig, cfg) {
4
+ config = { ...applyDefaults(cfg), db, app: appConfig };
5
+ }
6
+ export function getConfig() {
7
+ // if (!config) {
8
+ // throw new MissingConfigError('admins');
9
+ // }
10
+ return config;
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { BaseAdminsAddonConfigObject } from './interfaces';
2
+ declare function applyDefaults(config?: Partial<BaseAdminsAddonConfigObject>): BaseAdminsAddonConfigObject;
3
+ export default applyDefaults;
4
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/DEPRECATED_addon/defaults.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAIhE,iBAAS,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAAG,2BAA2B,CAEjG;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { deepMerge } from '@sqrzro/utility';
2
+ const defaults = {};
3
+ function applyDefaults(config) {
4
+ return deepMerge(defaults, config || {});
5
+ }
6
+ export default applyDefaults;
@@ -0,0 +1,6 @@
1
+ import type { AddonRegisterFunction } from '@sqrzro/addons';
2
+ import { BaseAdminsAddonConfigObject } from './interfaces';
3
+ export * from './interfaces';
4
+ declare const withAdmin: AddonRegisterFunction<Partial<BaseAdminsAddonConfigObject>>;
5
+ export default withAdmin;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/DEPRECATED_addon/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D,cAAc,cAAc,CAAC;AAE7B,QAAA,MAAM,SAAS,EAAE,qBAAqB,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAOzE,CAAC;AAEH,eAAe,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { setConfig } from './config';
2
+ export * from './interfaces';
3
+ const withAdmin = (config) => ({
4
+ register: (db, appConfig) => {
5
+ setConfig(db, appConfig, config);
6
+ },
7
+ schema: '@sqrzro/addon-admins/schema',
8
+ });
9
+ export default withAdmin;
@@ -0,0 +1,9 @@
1
+ import { AppConfig } from '@sqrzro/config';
2
+ import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
3
+ export interface BaseAdminsAddonConfigObject {
4
+ }
5
+ export interface AdminsAddonConfigObject extends BaseAdminsAddonConfigObject {
6
+ app: AppConfig;
7
+ db: NodePgDatabase;
8
+ }
9
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/DEPRECATED_addon/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,2BAA2B;CAAG;AAE/C,MAAM,WAAW,uBAAwB,SAAQ,2BAA2B;IACxE,GAAG,EAAE,SAAS,CAAC;IACf,EAAE,EAAE,cAAc,CAAC;CACtB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
+ import { AppConfig } from '@sqrzro/config';
1
2
  import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
2
3
  import type { AdminsAddonConfigObject, BaseAdminsAddonConfigObject } from './interfaces';
3
- export declare function setConfig(db: NodePgDatabase, cfg?: BaseAdminsAddonConfigObject): void;
4
+ export declare function setConfig(db: NodePgDatabase, appConfig: AppConfig, cfg?: Partial<BaseAdminsAddonConfigObject>): void;
4
5
  export declare function getConfig(): AdminsAddonConfigObject;
5
6
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/addon/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAIzF,wBAAgB,SAAS,CAAC,EAAE,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,2BAA2B,GAAG,IAAI,CAErF;AAED,wBAAgB,SAAS,IAAI,uBAAuB,CAKnD"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/addon/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAIzF,wBAAgB,SAAS,CACrB,EAAE,EAAE,cAAc,EAClB,SAAS,EAAE,SAAS,EACpB,GAAG,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAC3C,IAAI,CAEN;AAED,wBAAgB,SAAS,IAAI,uBAAuB,CAKnD"}
@@ -1,11 +1,11 @@
1
- import { MissingConfigError } from '@sqrzro/addons';
1
+ import applyDefaults from './defaults';
2
2
  let config = null;
3
- export function setConfig(db, cfg) {
4
- config = { ...cfg, db };
3
+ export function setConfig(db, appConfig, cfg) {
4
+ config = { ...applyDefaults(cfg), db, app: appConfig };
5
5
  }
6
6
  export function getConfig() {
7
- if (!config) {
8
- throw new MissingConfigError('admins');
9
- }
7
+ // if (!config) {
8
+ // throw new MissingConfigError('admins');
9
+ // }
10
10
  return config;
11
11
  }
@@ -0,0 +1,4 @@
1
+ import type { BaseAdminsAddonConfigObject } from './interfaces';
2
+ declare function applyDefaults(config?: Partial<BaseAdminsAddonConfigObject>): BaseAdminsAddonConfigObject;
3
+ export default applyDefaults;
4
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/addon/defaults.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAIhE,iBAAS,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAAG,2BAA2B,CAEjG;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { deepMerge } from '@sqrzro/utility';
2
+ const defaults = {};
3
+ function applyDefaults(config) {
4
+ return deepMerge(defaults, config || {});
5
+ }
6
+ export default applyDefaults;
@@ -1,6 +1,6 @@
1
1
  import type { AddonRegisterFunction } from '@sqrzro/addons';
2
2
  import { BaseAdminsAddonConfigObject } from './interfaces';
3
3
  export * from './interfaces';
4
- declare const withAdmins: AddonRegisterFunction<BaseAdminsAddonConfigObject>;
5
- export default withAdmins;
4
+ declare const withAdmin: AddonRegisterFunction<Partial<BaseAdminsAddonConfigObject>>;
5
+ export default withAdmin;
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/addon/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D,cAAc,cAAc,CAAC;AAE7B,QAAA,MAAM,UAAU,EAAE,qBAAqB,CAAC,2BAA2B,CAOjE,CAAC;AAEH,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/addon/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D,cAAc,cAAc,CAAC;AAE7B,QAAA,MAAM,SAAS,EAAE,qBAAqB,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAOzE,CAAC;AAEH,eAAe,SAAS,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import { setConfig } from './config';
2
2
  export * from './interfaces';
3
- const withAdmins = (config) => ({
4
- register: (db) => {
5
- setConfig(db, config);
3
+ const withAdmin = (config) => ({
4
+ register: (db, appConfig) => {
5
+ setConfig(db, appConfig, config);
6
6
  },
7
7
  schema: '@sqrzro/addon-admins/schema',
8
8
  });
9
- export default withAdmins;
9
+ export default withAdmin;
@@ -1,7 +1,9 @@
1
+ import { AppConfig } from '@sqrzro/config';
1
2
  import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
2
3
  export interface BaseAdminsAddonConfigObject {
3
4
  }
4
5
  export interface AdminsAddonConfigObject extends BaseAdminsAddonConfigObject {
6
+ app: AppConfig;
5
7
  db: NodePgDatabase;
6
8
  }
7
9
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/addon/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,2BAA2B;CAAG;AAE/C,MAAM,WAAW,uBAAwB,SAAQ,2BAA2B;IACxE,EAAE,EAAE,cAAc,CAAC;CACtB"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/addon/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,2BAA2B;CAAG;AAE/C,MAAM,WAAW,uBAAwB,SAAQ,2BAA2B;IACxE,GAAG,EAAE,SAAS,CAAC;IACf,EAAE,EAAE,cAAc,CAAC;CACtB"}
@@ -0,0 +1,7 @@
1
+ import createAdminRepository from '../repository';
2
+ export interface AdminsConfig {
3
+ repository: ReturnType<typeof createAdminRepository>;
4
+ }
5
+ export declare function setConfig(cfg: AdminsConfig): void;
6
+ export declare function getConfig(): AdminsConfig;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,YAAY;IACzB,UAAU,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;CACxD;AAID,wBAAgB,SAAS,CAAC,GAAG,EAAE,YAAY,QAE1C;AAED,wBAAgB,SAAS,IAAI,YAAY,CAKxC"}
@@ -0,0 +1,10 @@
1
+ let config = null;
2
+ export function setConfig(cfg) {
3
+ config = cfg;
4
+ }
5
+ export function getConfig() {
6
+ if (!config) {
7
+ throw new Error('Admin config has not been set');
8
+ }
9
+ return config;
10
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"AdminRepository.d.ts","sourceRoot":"","sources":["../../src/repositories/AdminRepository.ts"],"names":[],"mappings":"AAWA,OAAO,EAAgB,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAS,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAK9D,eAAO,MAAM,UAAU,MAAM,CAAC;;wBA2EA,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA1B0B,OAAO;;;;;;;;YAAP,OAAO;;;;;;;;;;;;;;AAwBrE,wBAGE"}
1
+ {"version":3,"file":"AdminRepository.d.ts","sourceRoot":"","sources":["../../src/repositories/AdminRepository.ts"],"names":[],"mappings":"AAUA,OAAO,EAAgB,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAS,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI9D,eAAO,MAAM,UAAU,MAAM,CAAC;;wBAqEA,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA1B0B,OAAO;;;;;;;;YAAP,OAAO;;;;;;;;;;;;;;AAwBrE,wBAGE"}
@@ -1,56 +1,49 @@
1
1
  import { extendRepository } from '@sqrzro/addons';
2
2
  import withAuth from '@sqrzro/addon-auth/repository';
3
- import { getAppConfig } from '@sqrzro/config';
3
+ import withOnboarding from '@sqrzro/addon-onboarding/repository';
4
+ import { db } from '@sqrzro/server/database';
4
5
  import { createRepository } from '@sqrzro/server/database';
5
6
  import { generateID } from '@sqrzro/server/utility';
6
7
  import { pick } from '@sqrzro/utility';
7
8
  import { and, count, eq } from 'drizzle-orm';
8
- import { getConfig } from '../addon/config';
9
9
  import { ADMIN_PREFIX } from '../utility/ids';
10
10
  import { adminTable } from '../schema';
11
- import withOnboarding from '@sqrzro/addon-onboarding/repository';
12
11
  export const ADMIN_ROLE = 100;
13
12
  const fillable = ['email', 'name'];
14
13
  const BaseAdminRepository = createRepository({
15
14
  indexes: { email: adminTable.email, id: adminTable.id },
16
15
  async makeCountQuery(conditions) {
17
- const [meta] = await getConfig()
18
- .db.select({ count: count() })
16
+ const [meta] = await db
17
+ .select({ count: count() })
19
18
  .from(adminTable)
20
19
  .where(and(...conditions));
21
20
  return meta.count;
22
21
  },
23
22
  async makeQuery(conditions, config) {
24
- return getConfig()
25
- .db.select()
23
+ return db
24
+ .select()
26
25
  .from(adminTable)
27
26
  .where(and(...conditions))
28
27
  .limit(config.limit)
29
28
  .offset(config.offset);
30
29
  },
31
30
  async makeDeleteMutation(id) {
32
- await getConfig()
33
- .db.update(adminTable)
34
- .set({ deletedAt: new Date() })
35
- .where(eq(adminTable.id, id));
31
+ await db.update(adminTable).set({ deletedAt: new Date() }).where(eq(adminTable.id, id));
36
32
  },
37
33
  async makeUndeleteMutation(id) {
38
- await getConfig()
39
- .db.update(adminTable)
40
- .set({ deletedAt: null })
41
- .where(eq(adminTable.id, id));
34
+ await db.update(adminTable).set({ deletedAt: null }).where(eq(adminTable.id, id));
42
35
  },
43
36
  async makeInsertMutation(data) {
44
37
  const values = {
45
38
  id: generateID(ADMIN_PREFIX),
46
39
  ...pick(data, fillable),
47
40
  };
48
- const [result] = await getConfig().db.insert(adminTable).values(values).returning();
41
+ const [result] = await db.insert(adminTable).values(values).returning();
49
42
  return result;
50
43
  },
51
44
  async makeUpdateMutation(data) {
52
- const [result] = await getConfig()
53
- .db.update(adminTable)
45
+ const [result] = await db
46
+ .update(adminTable)
54
47
  .set(data)
55
48
  .where(eq(adminTable.id, data.id))
56
49
  .returning();
@@ -60,9 +53,9 @@ const BaseAdminRepository = createRepository({
60
53
  prefix: ADMIN_PREFIX,
61
54
  });
62
55
  const AdminRepository = extendRepository(BaseAdminRepository, withAuth({ role: ADMIN_ROLE }), withOnboarding({
63
- app: getAppConfig().app.name,
64
- baseURL: getAppConfig().app.url,
56
+ baseURL: process.env.APP_URL,
65
57
  role: ADMIN_ROLE,
58
+ siteName: process.env.APP_NAME,
66
59
  }));
67
60
  export default {
68
61
  ...AdminRepository,
@@ -0,0 +1,114 @@
1
+ import { AdminID } from '../utility/ids';
2
+ import type { AdminData } from '../utility/interfaces';
3
+ export declare const ADMIN_ROLE = 100;
4
+ declare const _default: {
5
+ getByEmail: (email: string) => Promise<{
6
+ email: string;
7
+ id: `adm_${string}`;
8
+ name: string;
9
+ createdAt: Date;
10
+ deletedAt: Date | null;
11
+ } | null>;
12
+ create: ((data: AdminData) => Promise<{
13
+ email: string;
14
+ id: `adm_${string}`;
15
+ name: string;
16
+ createdAt: Date;
17
+ deletedAt: Date | null;
18
+ }>) & ((data: AdminData) => Promise<Promise<{
19
+ email: string;
20
+ id: `adm_${string}`;
21
+ name: string;
22
+ createdAt: Date;
23
+ deletedAt: Date | null;
24
+ }>>);
25
+ delete: ((id: `adm_${string}`) => Promise<void>) & ((id: string) => Promise<void>);
26
+ ensureByID: (id: `adm_${string}`) => Promise<{
27
+ email: string;
28
+ id: `adm_${string}`;
29
+ name: string;
30
+ createdAt: Date;
31
+ deletedAt: Date | null;
32
+ }>;
33
+ ensureByIndex: <K extends string>(key: K, value: any, fnConfig?: import("@sqrzro/server/database").SelectFunctionConfig<never, never> | undefined) => Promise<{
34
+ email: string;
35
+ id: `adm_${string}`;
36
+ name: string;
37
+ createdAt: Date;
38
+ deletedAt: Date | null;
39
+ }>;
40
+ ensureFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<{
41
+ email: string;
42
+ id: `adm_${string}`;
43
+ name: string;
44
+ createdAt: Date;
45
+ deletedAt: Date | null;
46
+ }>;
47
+ ensureID: (id: string | null | undefined) => `adm_${string}`;
48
+ ensureIDFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<`adm_${string}`>;
49
+ getAll: (fnConfig?: import("@sqrzro/server/database").SelectFunctionConfig<never, never> | undefined) => Promise<{
50
+ email: string;
51
+ id: `adm_${string}`;
52
+ name: string;
53
+ createdAt: Date;
54
+ deletedAt: Date | null;
55
+ }[]>;
56
+ getByID: (id: `adm_${string}`) => Promise<{
57
+ email: string;
58
+ id: `adm_${string}`;
59
+ name: string;
60
+ createdAt: Date;
61
+ deletedAt: Date | null;
62
+ } | null>;
63
+ getByIndex: <K extends string>(key: K, value: any, fnConfig?: import("@sqrzro/server/database").SelectFunctionConfig<never, never> | undefined) => Promise<{
64
+ email: string;
65
+ id: `adm_${string}`;
66
+ name: string;
67
+ createdAt: Date;
68
+ deletedAt: Date | null;
69
+ } | null>;
70
+ getFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<{
71
+ email: string;
72
+ id: `adm_${string}`;
73
+ name: string;
74
+ createdAt: Date;
75
+ deletedAt: Date | null;
76
+ } | null>;
77
+ getIDFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<`adm_${string}` | null>;
78
+ getPaginated: (fnConfig?: import("@sqrzro/server/database").PaginatedFunctionConfig<never, never> | undefined) => Promise<import("@sqrzro/server/utility").Paginated<{
79
+ email: string;
80
+ id: `adm_${string}`;
81
+ name: string;
82
+ createdAt: Date;
83
+ deletedAt: Date | null;
84
+ }>>;
85
+ guardID: {
86
+ (id: (string | null | undefined)[]): `adm_${string}`[];
87
+ (id: string | null | undefined): `adm_${string}` | null;
88
+ };
89
+ undelete: ((id: `adm_${string}`) => Promise<void>) & ((id: string) => Promise<void>);
90
+ update: ((data: Partial<AdminData> & {
91
+ id: AdminID;
92
+ }) => Promise<{
93
+ email: string;
94
+ id: `adm_${string}`;
95
+ name: string;
96
+ createdAt: Date;
97
+ deletedAt: Date | null;
98
+ }>) & ((data: Partial<AdminData> & {
99
+ id: AdminID;
100
+ }) => Promise<Promise<{
101
+ email: string;
102
+ id: `adm_${string}`;
103
+ name: string;
104
+ createdAt: Date;
105
+ deletedAt: Date | null;
106
+ }>>);
107
+ ensureFromSession: () => Promise<any>;
108
+ sendInvite: (user: {
109
+ id: string;
110
+ email: string;
111
+ }) => Promise<void>;
112
+ };
113
+ export default _default;
114
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAgB,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAS,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI9D,eAAO,MAAM,UAAU,MAAM,CAAC;;wBAqEA,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA1B0B,OAAO;;;;;;;;YAAP,OAAO;;;;;;;;;;;;;;AAwBrE,wBAGE"}
@@ -0,0 +1,63 @@
1
+ import { extendRepository } from '@sqrzro/addons';
2
+ import withAuth from '@sqrzro/addon-auth/repository';
3
+ import withOnboarding from '@sqrzro/addon-onboarding/repository';
4
+ import { db } from '@sqrzro/server/database';
5
+ import { createRepository } from '@sqrzro/server/database';
6
+ import { generateID } from '@sqrzro/server/utility';
7
+ import { pick } from '@sqrzro/utility';
8
+ import { and, count, eq } from 'drizzle-orm';
9
+ import { ADMIN_PREFIX } from '../utility/ids';
10
+ import { adminTable } from '../schema';
11
+ export const ADMIN_ROLE = 100;
12
+ const fillable = ['email', 'name'];
13
+ const BaseAdminRepository = createRepository({
14
+ indexes: { email: adminTable.email, id: adminTable.id },
15
+ async makeCountQuery(conditions) {
16
+ const [meta] = await db
17
+ .select({ count: count() })
18
+ .from(adminTable)
19
+ .where(and(...conditions));
20
+ return meta.count;
21
+ },
22
+ async makeQuery(conditions, config) {
23
+ return db
24
+ .select()
25
+ .from(adminTable)
26
+ .where(and(...conditions))
27
+ .limit(config.limit)
28
+ .offset(config.offset);
29
+ },
30
+ async makeDeleteMutation(id) {
31
+ await db.update(adminTable).set({ deletedAt: new Date() }).where(eq(adminTable.id, id));
32
+ },
33
+ async makeUndeleteMutation(id) {
34
+ await db.update(adminTable).set({ deletedAt: null }).where(eq(adminTable.id, id));
35
+ },
36
+ async makeInsertMutation(data) {
37
+ const values = {
38
+ id: generateID(ADMIN_PREFIX),
39
+ ...pick(data, fillable),
40
+ };
41
+ const [result] = await db.insert(adminTable).values(values).returning();
42
+ return result;
43
+ },
44
+ async makeUpdateMutation(data) {
45
+ const [result] = await db
46
+ .update(adminTable)
47
+ .set(data)
48
+ .where(eq(adminTable.id, data.id))
49
+ .returning();
50
+ return result;
51
+ },
52
+ paramKey: 'admins[0]',
53
+ prefix: ADMIN_PREFIX,
54
+ });
55
+ const AdminRepository = extendRepository(BaseAdminRepository, withAuth({ role: ADMIN_ROLE }), withOnboarding({
56
+ baseURL: process.env.APP_URL,
57
+ role: ADMIN_ROLE,
58
+ siteName: process.env.APP_NAME,
59
+ }));
60
+ export default {
61
+ ...AdminRepository,
62
+ getByEmail: async (email) => AdminRepository.getByIndex('email', email),
63
+ };
@@ -0,0 +1,119 @@
1
+ import { AdminID } from '../utility/ids';
2
+ import type { AdminData } from '../utility/interfaces';
3
+ export declare const ADMIN_ROLE = 100;
4
+ declare function createAdminRepository(site: {
5
+ name: string;
6
+ url: string;
7
+ }): {
8
+ getByEmail: (email: string) => Promise<{
9
+ email: string;
10
+ id: `adm_${string}`;
11
+ name: string;
12
+ createdAt: Date;
13
+ deletedAt: Date | null;
14
+ } | null>;
15
+ create: ((data: AdminData) => Promise<{
16
+ email: string;
17
+ id: `adm_${string}`;
18
+ name: string;
19
+ createdAt: Date;
20
+ deletedAt: Date | null;
21
+ }>) & ((data: AdminData) => Promise<Promise<{
22
+ email: string;
23
+ id: `adm_${string}`;
24
+ name: string;
25
+ createdAt: Date;
26
+ deletedAt: Date | null;
27
+ }>>);
28
+ delete: ((id: `adm_${string}`) => Promise<void>) & ((id: string) => Promise<void>);
29
+ ensureByID: (id: `adm_${string}`) => Promise<{
30
+ email: string;
31
+ id: `adm_${string}`;
32
+ name: string;
33
+ createdAt: Date;
34
+ deletedAt: Date | null;
35
+ }>;
36
+ ensureByIndex: <K extends string>(key: K, value: any, fnConfig?: import("@sqrzro/server/database").SelectFunctionConfig<never, never> | undefined) => Promise<{
37
+ email: string;
38
+ id: `adm_${string}`;
39
+ name: string;
40
+ createdAt: Date;
41
+ deletedAt: Date | null;
42
+ }>;
43
+ ensureFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<{
44
+ email: string;
45
+ id: `adm_${string}`;
46
+ name: string;
47
+ createdAt: Date;
48
+ deletedAt: Date | null;
49
+ }>;
50
+ ensureID: (id: string | null | undefined) => `adm_${string}`;
51
+ ensureIDFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<`adm_${string}`>;
52
+ getAll: (fnConfig?: import("@sqrzro/server/database").SelectFunctionConfig<never, never> | undefined) => Promise<{
53
+ email: string;
54
+ id: `adm_${string}`;
55
+ name: string;
56
+ createdAt: Date;
57
+ deletedAt: Date | null;
58
+ }[]>;
59
+ getByID: (id: `adm_${string}`) => Promise<{
60
+ email: string;
61
+ id: `adm_${string}`;
62
+ name: string;
63
+ createdAt: Date;
64
+ deletedAt: Date | null;
65
+ } | null>;
66
+ getByIndex: <K extends string>(key: K, value: any, fnConfig?: import("@sqrzro/server/database").SelectFunctionConfig<never, never> | undefined) => Promise<{
67
+ email: string;
68
+ id: `adm_${string}`;
69
+ name: string;
70
+ createdAt: Date;
71
+ deletedAt: Date | null;
72
+ } | null>;
73
+ getFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<{
74
+ email: string;
75
+ id: `adm_${string}`;
76
+ name: string;
77
+ createdAt: Date;
78
+ deletedAt: Date | null;
79
+ } | null>;
80
+ getIDFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<`adm_${string}` | null>;
81
+ getPaginated: (fnConfig?: import("@sqrzro/server/database").PaginatedFunctionConfig<never, never> | undefined) => Promise<import("@sqrzro/server/utility").Paginated<{
82
+ email: string;
83
+ id: `adm_${string}`;
84
+ name: string;
85
+ createdAt: Date;
86
+ deletedAt: Date | null;
87
+ }>>;
88
+ guardID: {
89
+ (id: (string | null | undefined)[]): `adm_${string}`[];
90
+ (id: string | null | undefined): `adm_${string}` | null;
91
+ };
92
+ undelete: ((id: `adm_${string}`) => Promise<void>) & ((id: string) => Promise<void>);
93
+ update: ((data: Partial<AdminData> & {
94
+ id: AdminID;
95
+ }) => Promise<{
96
+ email: string;
97
+ id: `adm_${string}`;
98
+ name: string;
99
+ createdAt: Date;
100
+ deletedAt: Date | null;
101
+ }>) & ((data: Partial<AdminData> & {
102
+ id: AdminID;
103
+ }) => Promise<Promise<{
104
+ email: string;
105
+ id: `adm_${string}`;
106
+ name: string;
107
+ createdAt: Date;
108
+ deletedAt: Date | null;
109
+ }>>);
110
+ ensureFromSession: () => Promise<any>;
111
+ sendInvite: (user: {
112
+ id: string;
113
+ email: string;
114
+ }) => Promise<void>;
115
+ };
116
+ export declare function setRepository(repo: ReturnType<typeof createAdminRepository>): void;
117
+ export declare function getRepository(): ReturnType<typeof createAdminRepository>;
118
+ export default createAdminRepository;
119
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repository/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAgB,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAS,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI9D,eAAO,MAAM,UAAU,MAAM,CAAC;AAI9B,iBAAS,qBAAqB,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE;wBAkEhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA1B0B,OAAO;;;;;;;;YAAP,OAAO;;;;;;;;;;;;;EA4BxE;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,GAAG,IAAI,CAElF;AAED,wBAAgB,aAAa,IAAI,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAKxE;AAED,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { extendRepository } from '@sqrzro/addons';
2
+ import withAuth from '@sqrzro/addon-auth/repository';
3
+ import withOnboarding from '@sqrzro/addon-onboarding/repository';
4
+ import { db } from '@sqrzro/server/database';
5
+ import { createRepository } from '@sqrzro/server/database';
6
+ import { generateID } from '@sqrzro/server/utility';
7
+ import { pick } from '@sqrzro/utility';
8
+ import { and, count, eq } from 'drizzle-orm';
9
+ import { ADMIN_PREFIX } from '../utility/ids';
10
+ import { adminTable } from '../schema';
11
+ export const ADMIN_ROLE = 100;
12
+ const fillable = ['email', 'name'];
13
+ function createAdminRepository(site) {
14
+ const BaseAdminRepository = createRepository({
15
+ indexes: { email: adminTable.email, id: adminTable.id },
16
+ async makeCountQuery(conditions) {
17
+ const [meta] = await db
18
+ .select({ count: count() })
19
+ .from(adminTable)
20
+ .where(and(...conditions));
21
+ return meta.count;
22
+ },
23
+ async makeQuery(conditions, config) {
24
+ return db
25
+ .select()
26
+ .from(adminTable)
27
+ .where(and(...conditions))
28
+ .limit(config.limit)
29
+ .offset(config.offset);
30
+ },
31
+ async makeDeleteMutation(id) {
32
+ await db.update(adminTable).set({ deletedAt: new Date() }).where(eq(adminTable.id, id));
33
+ },
34
+ async makeUndeleteMutation(id) {
35
+ await db.update(adminTable).set({ deletedAt: null }).where(eq(adminTable.id, id));
36
+ },
37
+ async makeInsertMutation(data) {
38
+ const values = {
39
+ id: generateID(ADMIN_PREFIX),
40
+ ...pick(data, fillable),
41
+ };
42
+ const [result] = await db.insert(adminTable).values(values).returning();
43
+ return result;
44
+ },
45
+ async makeUpdateMutation(data) {
46
+ const [result] = await db
47
+ .update(adminTable)
48
+ .set(data)
49
+ .where(eq(adminTable.id, data.id))
50
+ .returning();
51
+ return result;
52
+ },
53
+ paramKey: 'admins[0]',
54
+ prefix: ADMIN_PREFIX,
55
+ });
56
+ const AdminRepository = extendRepository(BaseAdminRepository, withAuth({ role: ADMIN_ROLE }), withOnboarding({
57
+ baseURL: site.url,
58
+ role: ADMIN_ROLE,
59
+ siteName: site.name,
60
+ }));
61
+ return {
62
+ ...AdminRepository,
63
+ getByEmail: async (email) => AdminRepository.getByIndex('email', email),
64
+ };
65
+ }
66
+ let repository = null;
67
+ export function setRepository(repo) {
68
+ repository = repo;
69
+ }
70
+ export function getRepository() {
71
+ if (!repository) {
72
+ throw new Error('Admin repository has not been set');
73
+ }
74
+ return repository;
75
+ }
76
+ export default createAdminRepository;
@@ -1 +1 @@
1
- {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/rules/id.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAIpB,OAAO,EAAE,OAAO,EAAgB,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAInD,iBAAe,WAAW,CAAC,CAAC,SAAS;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,CAGjG;AAED,iBAAS,cAAc;;;EAGtB;AAED,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/rules/id.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAMpB,OAAO,EAAE,OAAO,EAAgB,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,iBAAe,WAAW,CAAC,CAAC,SAAS;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,CAIjG;AAED,iBAAS,cAAc;;;EAGtB;AAED,eAAe,cAAc,CAAC"}
package/dist/rules/id.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import z from 'zod';
2
2
  import { createRule, getExistsTransformer } from '@sqrzro/server/forms';
3
- import { ADMIN_PREFIX } from '../utility/ids';
4
3
  import AdminRepository from '../repositories/AdminRepository';
4
+ import { ADMIN_PREFIX } from '../utility/ids';
5
5
  async function transformer(data) {
6
6
  const admin = await getExistsTransformer('adminID', data.adminID, AdminRepository.getByID);
7
7
  return { ...data, admin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqrzro/addon-admins",
3
3
  "type": "module",
4
- "version": "4.0.0-alpha.3",
4
+ "version": "4.0.0-alpha.6",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "ISC",
@@ -10,10 +10,6 @@
10
10
  "default": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts"
12
12
  },
13
- "./addon": {
14
- "default": "./dist/addon/index.js",
15
- "types": "./dist/addon/index.d.ts"
16
- },
17
13
  "./schema": {
18
14
  "default": "./dist/schema.js",
19
15
  "types": "./dist/schema.d.ts"
@@ -25,21 +21,20 @@
25
21
  "dependencies": {
26
22
  "drizzle-orm": "^0.45.1",
27
23
  "zod": "^4.3.6",
28
- "@sqrzro/addon-auth": "^4.0.0-alpha.4",
29
- "@sqrzro/addons": "^4.0.0-alpha.3",
30
- "@sqrzro/addon-onboarding": "^4.0.0-alpha.6",
31
- "@sqrzro/admin": "^4.0.0-alpha.14",
32
- "@sqrzro/config": "^4.0.0-alpha.1",
33
- "@sqrzro/server": "^4.0.0-alpha.33",
34
- "@sqrzro/utility": "^4.0.0-alpha.15",
35
- "@sqrzro/ui": "^4.0.0-alpha.39"
24
+ "@sqrzro/addons": "^4.0.0-alpha.6",
25
+ "@sqrzro/utility": "^4.0.0-alpha.16",
26
+ "@sqrzro/addon-auth": "^4.0.0-alpha.7",
27
+ "@sqrzro/server": "^4.0.0-alpha.34",
28
+ "@sqrzro/addon-onboarding": "^4.0.0-alpha.9",
29
+ "@sqrzro/admin": "^4.0.0-alpha.17",
30
+ "@sqrzro/ui": "^4.0.0-alpha.42"
36
31
  },
37
32
  "devDependencies": {
38
33
  "@types/react": "^19.2.14",
39
34
  "prettier": "^3.8.1",
40
35
  "typescript": "^5.9.3",
41
- "szx": "^4.0.0-alpha.5",
42
- "@sqrzro/prettier-config": "^4.0.0-alpha.3"
36
+ "@sqrzro/prettier-config": "^4.0.0-alpha.3",
37
+ "szx": "^4.0.0-alpha.5"
43
38
  },
44
39
  "peerDependencies": {
45
40
  "next": "^16.1.6",