dpdp-kit 0.2.0 → 0.4.0

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 (46) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +240 -17
  3. package/dist/access.d.ts +111 -0
  4. package/dist/audit.d.ts +3 -1
  5. package/dist/breach.d.ts +170 -0
  6. package/dist/chunk-2ELTZSW3.js +94 -0
  7. package/dist/chunk-5TVA2TKG.js +37 -0
  8. package/dist/chunk-HXVP446N.js +1051 -0
  9. package/dist/chunk-KLMR7S7I.js +438 -0
  10. package/dist/cli.js +53 -17
  11. package/dist/config.d.ts +69 -0
  12. package/dist/data-access.d.ts +6 -2
  13. package/dist/ddl.d.ts +10 -0
  14. package/dist/dpdp.d.ts +210 -0
  15. package/dist/drizzle.d.ts +403 -11
  16. package/dist/drizzle.js +209 -56
  17. package/dist/errors.d.ts +1 -1
  18. package/dist/express.d.ts +17 -1
  19. package/dist/express.js +10 -2
  20. package/dist/fastify.d.ts +41 -0
  21. package/dist/fastify.js +25 -0
  22. package/dist/guard.d.ts +19 -0
  23. package/dist/hono.d.ts +16 -1
  24. package/dist/hono.js +11 -2
  25. package/dist/index.d.ts +7 -4
  26. package/dist/index.js +420 -100
  27. package/dist/mongodb.d.ts +87 -0
  28. package/dist/mongodb.js +344 -0
  29. package/dist/nestjs.d.ts +65 -0
  30. package/dist/nestjs.js +41 -0
  31. package/dist/postgres.d.ts +45 -0
  32. package/dist/postgres.js +27 -0
  33. package/dist/prisma.d.ts +43 -0
  34. package/dist/prisma.js +281 -0
  35. package/dist/protect.d.ts +74 -0
  36. package/dist/protect.js +114 -0
  37. package/dist/retention.d.ts +1 -1
  38. package/dist/run-audit.d.ts +13 -1
  39. package/dist/safeguards.d.ts +23 -0
  40. package/dist/schedule.d.ts +37 -0
  41. package/dist/schedule.js +66 -0
  42. package/dist/schema-check.d.ts +25 -8
  43. package/dist/store.d.ts +11 -1
  44. package/package.json +58 -5
  45. package/dist/chunk-FGZAH2NF.js +0 -16
  46. package/dist/chunk-KVTUMHXO.js +0 -491
package/dist/drizzle.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import { type PgDatabase } from "drizzle-orm/pg-core";
2
+ import type { AccessLogStore } from "./access.js";
3
+ import type { Breach, BreachStore } from "./breach.js";
2
4
  import type { DataAccess } from "./data-access.js";
3
5
  import type { RequestStatus, RequestType, TaskKind, TaskStatus } from "./records.js";
4
6
  import type { Schema } from "./schema-check.js";
5
7
  import type { DpdpStore } from "./store.js";
8
+ export { ACCESS_LOG_DDL, BREACH_DDL, CONSENT_EVENTS_DDL, DPDP_DDL, RECORDS_DDL } from "./ddl.js";
6
9
  /**
7
10
  * The consent events table. Export it from your Drizzle schema so drizzle-kit creates it:
8
11
  *
@@ -208,8 +211,6 @@ export declare const consentEvents: import("drizzle-orm/pg-core").PgTableWithCol
208
211
  };
209
212
  dialect: 'pg';
210
213
  }>;
211
- /** The same table as plain SQL, if you don't use drizzle-kit for migrations. */
212
- export declare const CONSENT_EVENTS_DDL = "CREATE TABLE IF NOT EXISTS dpdp_consent_events (\n subject_id text NOT NULL,\n seq integer NOT NULL,\n action text NOT NULL CHECK (action IN ('grant', 'withdraw')),\n purposes jsonb NOT NULL,\n notice_version text,\n language text,\n channel text,\n evidence jsonb,\n at timestamptz NOT NULL,\n prev_hash text,\n hash text NOT NULL,\n PRIMARY KEY (subject_id, seq)\n);";
213
214
  /** Rights requests (Sections 11–14). Export it from your Drizzle schema with `consentEvents`. */
214
215
  export declare const rightsRequests: import("drizzle-orm/pg-core").PgTableWithColumns<{
215
216
  name: "dpdp_requests";
@@ -684,17 +685,409 @@ export declare const erasureTasks: import("drizzle-orm/pg-core").PgTableWithColu
684
685
  };
685
686
  dialect: 'pg';
686
687
  }>;
687
- /** Rights requests and erasure tasks as plain SQL, if you don't use drizzle-kit for migrations. */
688
- export declare const RECORDS_DDL = "CREATE TABLE IF NOT EXISTS dpdp_requests (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n type text NOT NULL,\n status text NOT NULL,\n opened_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n closed_at timestamptz,\n details jsonb,\n history jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_requests_subject_idx ON dpdp_requests (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_requests_status_due_idx ON dpdp_requests (status, due_at);\nCREATE TABLE IF NOT EXISTS dpdp_erasure_tasks (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n reason text NOT NULL,\n kind text NOT NULL,\n table_key text,\n fields jsonb,\n processor text,\n purposes jsonb,\n created_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n status text NOT NULL,\n attempts integer NOT NULL,\n claimed_at timestamptz,\n done_at timestamptz,\n affected integer,\n last_error text,\n note text\n);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_subject_idx ON dpdp_erasure_tasks (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_status_due_idx ON dpdp_erasure_tasks (status, due_at);";
689
- /** Every dpdp-kit table as plain SQL. */
690
- export declare const DPDP_DDL = "CREATE TABLE IF NOT EXISTS dpdp_consent_events (\n subject_id text NOT NULL,\n seq integer NOT NULL,\n action text NOT NULL CHECK (action IN ('grant', 'withdraw')),\n purposes jsonb NOT NULL,\n notice_version text,\n language text,\n channel text,\n evidence jsonb,\n at timestamptz NOT NULL,\n prev_hash text,\n hash text NOT NULL,\n PRIMARY KEY (subject_id, seq)\n);\nCREATE TABLE IF NOT EXISTS dpdp_requests (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n type text NOT NULL,\n status text NOT NULL,\n opened_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n closed_at timestamptz,\n details jsonb,\n history jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_requests_subject_idx ON dpdp_requests (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_requests_status_due_idx ON dpdp_requests (status, due_at);\nCREATE TABLE IF NOT EXISTS dpdp_erasure_tasks (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n reason text NOT NULL,\n kind text NOT NULL,\n table_key text,\n fields jsonb,\n processor text,\n purposes jsonb,\n created_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n status text NOT NULL,\n attempts integer NOT NULL,\n claimed_at timestamptz,\n done_at timestamptz,\n affected integer,\n last_error text,\n note text\n);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_subject_idx ON dpdp_erasure_tasks (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_status_due_idx ON dpdp_erasure_tasks (status, due_at);";
688
+ /**
689
+ * The access log (Rule 6(1)(c) and (e)): who accessed whose personal data, when, for which purpose.
690
+ * Export it from your Drizzle schema with `consentEvents`.
691
+ */
692
+ export declare const accessLog: import("drizzle-orm/pg-core").PgTableWithColumns<{
693
+ name: "dpdp_access_log";
694
+ schema: undefined;
695
+ columns: {
696
+ id: import("drizzle-orm/pg-core").PgColumn<{
697
+ name: "id";
698
+ tableName: "dpdp_access_log";
699
+ dataType: "string";
700
+ columnType: "PgText";
701
+ data: string;
702
+ driverParam: string;
703
+ notNull: true;
704
+ hasDefault: false;
705
+ isPrimaryKey: true;
706
+ isAutoincrement: false;
707
+ hasRuntimeDefault: false;
708
+ enumValues: [string, ...string[]];
709
+ baseColumn: never;
710
+ identity: undefined;
711
+ generated: undefined;
712
+ }, {}, {}>;
713
+ at: import("drizzle-orm/pg-core").PgColumn<{
714
+ name: string;
715
+ tableName: "dpdp_access_log";
716
+ dataType: "date";
717
+ columnType: "PgTimestamp";
718
+ data: Date;
719
+ driverParam: string;
720
+ notNull: true;
721
+ hasDefault: false;
722
+ isPrimaryKey: false;
723
+ isAutoincrement: false;
724
+ hasRuntimeDefault: false;
725
+ enumValues: undefined;
726
+ baseColumn: never;
727
+ identity: undefined;
728
+ generated: undefined;
729
+ }, {}, {}>;
730
+ actor: import("drizzle-orm/pg-core").PgColumn<{
731
+ name: "actor";
732
+ tableName: "dpdp_access_log";
733
+ dataType: "string";
734
+ columnType: "PgText";
735
+ data: string;
736
+ driverParam: string;
737
+ notNull: true;
738
+ hasDefault: false;
739
+ isPrimaryKey: false;
740
+ isAutoincrement: false;
741
+ hasRuntimeDefault: false;
742
+ enumValues: [string, ...string[]];
743
+ baseColumn: never;
744
+ identity: undefined;
745
+ generated: undefined;
746
+ }, {}, {}>;
747
+ subjectId: import("drizzle-orm/pg-core").PgColumn<{
748
+ name: "subject_id";
749
+ tableName: "dpdp_access_log";
750
+ dataType: "string";
751
+ columnType: "PgText";
752
+ data: string;
753
+ driverParam: string;
754
+ notNull: true;
755
+ hasDefault: false;
756
+ isPrimaryKey: false;
757
+ isAutoincrement: false;
758
+ hasRuntimeDefault: false;
759
+ enumValues: [string, ...string[]];
760
+ baseColumn: never;
761
+ identity: undefined;
762
+ generated: undefined;
763
+ }, {}, {}>;
764
+ action: import("drizzle-orm/pg-core").PgColumn<{
765
+ name: "action";
766
+ tableName: "dpdp_access_log";
767
+ dataType: "string";
768
+ columnType: "PgText";
769
+ data: string;
770
+ driverParam: string;
771
+ notNull: true;
772
+ hasDefault: false;
773
+ isPrimaryKey: false;
774
+ isAutoincrement: false;
775
+ hasRuntimeDefault: false;
776
+ enumValues: [string, ...string[]];
777
+ baseColumn: never;
778
+ identity: undefined;
779
+ generated: undefined;
780
+ }, {}, {}>;
781
+ purpose: import("drizzle-orm/pg-core").PgColumn<{
782
+ name: "purpose";
783
+ tableName: "dpdp_access_log";
784
+ dataType: "string";
785
+ columnType: "PgText";
786
+ data: string;
787
+ driverParam: string;
788
+ notNull: true;
789
+ hasDefault: false;
790
+ isPrimaryKey: false;
791
+ isAutoincrement: false;
792
+ hasRuntimeDefault: false;
793
+ enumValues: [string, ...string[]];
794
+ baseColumn: never;
795
+ identity: undefined;
796
+ generated: undefined;
797
+ }, {}, {}>;
798
+ fields: import("drizzle-orm/pg-core").PgColumn<{
799
+ name: "fields";
800
+ tableName: "dpdp_access_log";
801
+ dataType: "json";
802
+ columnType: "PgJsonb";
803
+ data: string[];
804
+ driverParam: unknown;
805
+ notNull: false;
806
+ hasDefault: false;
807
+ isPrimaryKey: false;
808
+ isAutoincrement: false;
809
+ hasRuntimeDefault: false;
810
+ enumValues: undefined;
811
+ baseColumn: never;
812
+ identity: undefined;
813
+ generated: undefined;
814
+ }, {}, {
815
+ $type: string[];
816
+ }>;
817
+ outOfPurpose: import("drizzle-orm/pg-core").PgColumn<{
818
+ name: "out_of_purpose";
819
+ tableName: "dpdp_access_log";
820
+ dataType: "json";
821
+ columnType: "PgJsonb";
822
+ data: string[];
823
+ driverParam: unknown;
824
+ notNull: false;
825
+ hasDefault: false;
826
+ isPrimaryKey: false;
827
+ isAutoincrement: false;
828
+ hasRuntimeDefault: false;
829
+ enumValues: undefined;
830
+ baseColumn: never;
831
+ identity: undefined;
832
+ generated: undefined;
833
+ }, {}, {
834
+ $type: string[];
835
+ }>;
836
+ reason: import("drizzle-orm/pg-core").PgColumn<{
837
+ name: "reason";
838
+ tableName: "dpdp_access_log";
839
+ dataType: "string";
840
+ columnType: "PgText";
841
+ data: string;
842
+ driverParam: string;
843
+ notNull: false;
844
+ hasDefault: false;
845
+ isPrimaryKey: false;
846
+ isAutoincrement: false;
847
+ hasRuntimeDefault: false;
848
+ enumValues: [string, ...string[]];
849
+ baseColumn: never;
850
+ identity: undefined;
851
+ generated: undefined;
852
+ }, {}, {}>;
853
+ evidence: import("drizzle-orm/pg-core").PgColumn<{
854
+ name: "evidence";
855
+ tableName: "dpdp_access_log";
856
+ dataType: "json";
857
+ columnType: "PgJsonb";
858
+ data: Record<string, string>;
859
+ driverParam: unknown;
860
+ notNull: false;
861
+ hasDefault: false;
862
+ isPrimaryKey: false;
863
+ isAutoincrement: false;
864
+ hasRuntimeDefault: false;
865
+ enumValues: undefined;
866
+ baseColumn: never;
867
+ identity: undefined;
868
+ generated: undefined;
869
+ }, {}, {
870
+ $type: Record<string, string>;
871
+ }>;
872
+ };
873
+ dialect: 'pg';
874
+ }>;
875
+ /** Personal data breaches (Section 8(6), Rule 7). Export it from your Drizzle schema with `consentEvents`. */
876
+ export declare const breaches: import("drizzle-orm/pg-core").PgTableWithColumns<{
877
+ name: "dpdp_breaches";
878
+ schema: undefined;
879
+ columns: {
880
+ id: import("drizzle-orm/pg-core").PgColumn<{
881
+ name: "id";
882
+ tableName: "dpdp_breaches";
883
+ dataType: "string";
884
+ columnType: "PgText";
885
+ data: string;
886
+ driverParam: string;
887
+ notNull: true;
888
+ hasDefault: false;
889
+ isPrimaryKey: true;
890
+ isAutoincrement: false;
891
+ hasRuntimeDefault: false;
892
+ enumValues: [string, ...string[]];
893
+ baseColumn: never;
894
+ identity: undefined;
895
+ generated: undefined;
896
+ }, {}, {}>;
897
+ status: import("drizzle-orm/pg-core").PgColumn<{
898
+ name: "status";
899
+ tableName: "dpdp_breaches";
900
+ dataType: "string";
901
+ columnType: "PgText";
902
+ data: "closed" | "open";
903
+ driverParam: string;
904
+ notNull: true;
905
+ hasDefault: false;
906
+ isPrimaryKey: false;
907
+ isAutoincrement: false;
908
+ hasRuntimeDefault: false;
909
+ enumValues: [string, ...string[]];
910
+ baseColumn: never;
911
+ identity: undefined;
912
+ generated: undefined;
913
+ }, {}, {
914
+ $type: "closed" | "open";
915
+ }>;
916
+ awareAt: import("drizzle-orm/pg-core").PgColumn<{
917
+ name: string;
918
+ tableName: "dpdp_breaches";
919
+ dataType: "date";
920
+ columnType: "PgTimestamp";
921
+ data: Date;
922
+ driverParam: string;
923
+ notNull: true;
924
+ hasDefault: false;
925
+ isPrimaryKey: false;
926
+ isAutoincrement: false;
927
+ hasRuntimeDefault: false;
928
+ enumValues: undefined;
929
+ baseColumn: never;
930
+ identity: undefined;
931
+ generated: undefined;
932
+ }, {}, {}>;
933
+ reportDueAt: import("drizzle-orm/pg-core").PgColumn<{
934
+ name: string;
935
+ tableName: "dpdp_breaches";
936
+ dataType: "date";
937
+ columnType: "PgTimestamp";
938
+ data: Date;
939
+ driverParam: string;
940
+ notNull: true;
941
+ hasDefault: false;
942
+ isPrimaryKey: false;
943
+ isAutoincrement: false;
944
+ hasRuntimeDefault: false;
945
+ enumValues: undefined;
946
+ baseColumn: never;
947
+ identity: undefined;
948
+ generated: undefined;
949
+ }, {}, {}>;
950
+ data: import("drizzle-orm/pg-core").PgColumn<{
951
+ name: "data";
952
+ tableName: "dpdp_breaches";
953
+ dataType: "json";
954
+ columnType: "PgJsonb";
955
+ data: Breach;
956
+ driverParam: unknown;
957
+ notNull: true;
958
+ hasDefault: false;
959
+ isPrimaryKey: false;
960
+ isAutoincrement: false;
961
+ hasRuntimeDefault: false;
962
+ enumValues: undefined;
963
+ baseColumn: never;
964
+ identity: undefined;
965
+ generated: undefined;
966
+ }, {}, {
967
+ $type: Breach;
968
+ }>;
969
+ };
970
+ dialect: 'pg';
971
+ }>;
972
+ /** The people affected by each breach, and whether they've been told (Rule 7(1)). */
973
+ export declare const breachNotices: import("drizzle-orm/pg-core").PgTableWithColumns<{
974
+ name: "dpdp_breach_notices";
975
+ schema: undefined;
976
+ columns: {
977
+ breachId: import("drizzle-orm/pg-core").PgColumn<{
978
+ name: "breach_id";
979
+ tableName: "dpdp_breach_notices";
980
+ dataType: "string";
981
+ columnType: "PgText";
982
+ data: string;
983
+ driverParam: string;
984
+ notNull: true;
985
+ hasDefault: false;
986
+ isPrimaryKey: false;
987
+ isAutoincrement: false;
988
+ hasRuntimeDefault: false;
989
+ enumValues: [string, ...string[]];
990
+ baseColumn: never;
991
+ identity: undefined;
992
+ generated: undefined;
993
+ }, {}, {}>;
994
+ subjectId: import("drizzle-orm/pg-core").PgColumn<{
995
+ name: "subject_id";
996
+ tableName: "dpdp_breach_notices";
997
+ dataType: "string";
998
+ columnType: "PgText";
999
+ data: string;
1000
+ driverParam: string;
1001
+ notNull: true;
1002
+ hasDefault: false;
1003
+ isPrimaryKey: false;
1004
+ isAutoincrement: false;
1005
+ hasRuntimeDefault: false;
1006
+ enumValues: [string, ...string[]];
1007
+ baseColumn: never;
1008
+ identity: undefined;
1009
+ generated: undefined;
1010
+ }, {}, {}>;
1011
+ status: import("drizzle-orm/pg-core").PgColumn<{
1012
+ name: "status";
1013
+ tableName: "dpdp_breach_notices";
1014
+ dataType: "string";
1015
+ columnType: "PgText";
1016
+ data: "pending" | "sent";
1017
+ driverParam: string;
1018
+ notNull: true;
1019
+ hasDefault: false;
1020
+ isPrimaryKey: false;
1021
+ isAutoincrement: false;
1022
+ hasRuntimeDefault: false;
1023
+ enumValues: [string, ...string[]];
1024
+ baseColumn: never;
1025
+ identity: undefined;
1026
+ generated: undefined;
1027
+ }, {}, {
1028
+ $type: "pending" | "sent";
1029
+ }>;
1030
+ addedAt: import("drizzle-orm/pg-core").PgColumn<{
1031
+ name: string;
1032
+ tableName: "dpdp_breach_notices";
1033
+ dataType: "date";
1034
+ columnType: "PgTimestamp";
1035
+ data: Date;
1036
+ driverParam: string;
1037
+ notNull: true;
1038
+ hasDefault: false;
1039
+ isPrimaryKey: false;
1040
+ isAutoincrement: false;
1041
+ hasRuntimeDefault: false;
1042
+ enumValues: undefined;
1043
+ baseColumn: never;
1044
+ identity: undefined;
1045
+ generated: undefined;
1046
+ }, {}, {}>;
1047
+ sentAt: import("drizzle-orm/pg-core").PgColumn<{
1048
+ name: string;
1049
+ tableName: "dpdp_breach_notices";
1050
+ dataType: "date";
1051
+ columnType: "PgTimestamp";
1052
+ data: Date;
1053
+ driverParam: string;
1054
+ notNull: false;
1055
+ hasDefault: false;
1056
+ isPrimaryKey: false;
1057
+ isAutoincrement: false;
1058
+ hasRuntimeDefault: false;
1059
+ enumValues: undefined;
1060
+ baseColumn: never;
1061
+ identity: undefined;
1062
+ generated: undefined;
1063
+ }, {}, {}>;
1064
+ channel: import("drizzle-orm/pg-core").PgColumn<{
1065
+ name: "channel";
1066
+ tableName: "dpdp_breach_notices";
1067
+ dataType: "string";
1068
+ columnType: "PgText";
1069
+ data: string;
1070
+ driverParam: string;
1071
+ notNull: false;
1072
+ hasDefault: false;
1073
+ isPrimaryKey: false;
1074
+ isAutoincrement: false;
1075
+ hasRuntimeDefault: false;
1076
+ enumValues: [string, ...string[]];
1077
+ baseColumn: never;
1078
+ identity: undefined;
1079
+ generated: undefined;
1080
+ }, {}, {}>;
1081
+ };
1082
+ dialect: 'pg';
1083
+ }>;
691
1084
  type AnyPgDatabase = PgDatabase<any, any, any>;
692
1085
  /**
693
1086
  * Store on Postgres through Drizzle: consent events, rights requests and erasure tasks. Works with
694
1087
  * node-postgres, postgres.js, Neon, PGlite and other Drizzle Postgres drivers. Needs the tables
695
- * `consentEvents`, `rightsRequests` and `erasureTasks` (or `DPDP_DDL`).
1088
+ * `consentEvents`, `rightsRequests`, `erasureTasks`, `accessLog`, `breaches` and `breachNotices` (or `DPDP_DDL`).
696
1089
  */
697
- export declare function drizzleStore(db: AnyPgDatabase): DpdpStore;
1090
+ export declare function drizzleStore(db: AnyPgDatabase): DpdpStore & AccessLogStore & BreachStore;
698
1091
  /**
699
1092
  * Read a Drizzle schema module (Postgres, MySQL or SQLite) for `checkSchema()`. Pass the module
700
1093
  * itself, so every exported table is found:
@@ -708,10 +1101,9 @@ export declare function drizzleSchema(module: Record<string, unknown>): Schema;
708
1101
  /**
709
1102
  * Data access for your own Postgres tables through Drizzle, for access summaries and erasure.
710
1103
  * Pass your schema module if data map names are Drizzle property names (`userId`) rather than
711
- * database column names (`user_id`). Erasure sets fields to NULL, so erasable columns must be
712
- * nullable; a NOT NULL column makes the task fail with the database's message.
1104
+ * database column names (`user_id`). Erasure writes each field's `erase` replacement, or NULL;
1105
+ * `dpdp-kit audit --schema` checks that each column can take it.
713
1106
  */
714
1107
  export declare function drizzleData(db: AnyPgDatabase, options?: {
715
1108
  schema?: Record<string, unknown>;
716
1109
  }): DataAccess;
717
- export {};