@toolproof-core/lib 1.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 (40) hide show
  1. package/dist/constants/constants.d.ts +94 -0
  2. package/dist/constants/constants.d.ts.map +1 -0
  3. package/dist/constants/constants.js +39 -0
  4. package/dist/constants/constants.js.map +1 -0
  5. package/dist/declarations/constants.d.ts +94 -0
  6. package/dist/declarations/constants.d.ts.map +1 -0
  7. package/dist/declarations/constants.js +39 -0
  8. package/dist/declarations/constants.js.map +1 -0
  9. package/dist/declarations/types.d.ts +10 -0
  10. package/dist/declarations/types.d.ts.map +1 -0
  11. package/dist/declarations/types.js +2 -0
  12. package/dist/declarations/types.js.map +1 -0
  13. package/dist/declarations/typesTS.d.ts +11 -0
  14. package/dist/declarations/typesTS.d.ts.map +1 -0
  15. package/dist/declarations/typesTS.js +2 -0
  16. package/dist/declarations/typesTS.js.map +1 -0
  17. package/dist/firebase/firebaseAdminHelpers.d.ts +33 -0
  18. package/dist/firebase/firebaseAdminHelpers.d.ts.map +1 -0
  19. package/dist/firebase/firebaseAdminHelpers.js +150 -0
  20. package/dist/firebase/firebaseAdminHelpers.js.map +1 -0
  21. package/dist/firebase/firebaseAdminInit.d.ts +4 -0
  22. package/dist/firebase/firebaseAdminInit.d.ts.map +1 -0
  23. package/dist/firebase/firebaseAdminInit.js +37 -0
  24. package/dist/firebase/firebaseAdminInit.js.map +1 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +4 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types/types.d.ts +10 -0
  30. package/dist/types/types.d.ts.map +1 -0
  31. package/dist/types/types.js +2 -0
  32. package/dist/types/types.js.map +1 -0
  33. package/package.json +36 -0
  34. package/src/constants/constants.ts +39 -0
  35. package/src/firebase/firebaseAdminHelpers.ts +189 -0
  36. package/src/firebase/firebaseAdminInit.ts +38 -0
  37. package/src/index.ts +3 -0
  38. package/src/types/types.ts +17 -0
  39. package/tsconfig.json +15 -0
  40. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,94 @@
1
+ export declare const CONSTANTS: {
2
+ readonly PERSISTENCE: {
3
+ readonly BUCKETS: {
4
+ readonly tp_resources: "tp-resources";
5
+ readonly tp_strategies: "tp-strategies";
6
+ };
7
+ readonly COLLECTIONS: {
8
+ readonly resources: "resources";
9
+ readonly members: "members";
10
+ };
11
+ };
12
+ readonly ENGINE: {
13
+ readonly GRAPHS: {
14
+ readonly GraphRunStrategy: "GraphRunStrategy";
15
+ readonly GraphBuildStrategy: "GraphBuildStrategy";
16
+ };
17
+ };
18
+ readonly COSMOS: {
19
+ readonly TYPE_Boolean: "TYPE-Boolean";
20
+ readonly TYPE_Natural: "TYPE-Natural";
21
+ readonly TYPE_ResourceType: "TYPE-ResourceType";
22
+ readonly TYPE_Job: "TYPE-Job";
23
+ readonly TYPE_Error: "TYPE-Error";
24
+ readonly TYPE_RawStrategy: "TYPE-RawStrategy";
25
+ readonly TYPE_RunnableStrategy: "TYPE-RunnableStrategy";
26
+ readonly TYPE_StrategyRun: "TYPE-StrategyRun";
27
+ readonly ROLE_Manual: "ROLE-Manual";
28
+ readonly ROLE_ErrorOutput: "ROLE-ErrorOutput";
29
+ readonly ROLE_LessThanSource: "ROLE-LessThanSource";
30
+ readonly ROLE_LessThanTarget: "ROLE-LessThanTarget";
31
+ readonly ROLE_LessThanDecision: "ROLE-LessThanDecision";
32
+ readonly JOB_LessThan: "JOB-LessThan";
33
+ readonly BOOLEAN_false: "RESOURCE-qadnfFGjZsjpqLI0Du1d";
34
+ readonly BOOLEAN_true: "RESOURCE-iZX1cxZ9ImJRzty9Ob4G";
35
+ };
36
+ readonly IDENTIFIABLES: {
37
+ readonly PREFIXES: {
38
+ readonly BranchStepIdentity: "BRANCH_STEP-";
39
+ readonly ForStepIdentity: "FOR_STEP-";
40
+ readonly GoalIdentity: "GOAL-";
41
+ readonly JobIdentity: "JOB-";
42
+ readonly JobStepIdentity: "JOB_STEP-";
43
+ readonly ResourceIdentity: "RESOURCE-";
44
+ readonly ResourceRoleIdentity: "ROLE-";
45
+ readonly ResourceTypeIdentity: "TYPE-";
46
+ readonly RunnableStrategyIdentity: "RUNNABLE_STRATEGY-";
47
+ readonly StrategyRunIdentity: "STRATEGY_RUN-";
48
+ readonly StrategyThreadIdentity: "STRATEGY_THREAD-";
49
+ readonly WhileStepIdentity: "WHILE_STEP-";
50
+ };
51
+ readonly NAMES: {
52
+ readonly BranchStep: "BranchStep";
53
+ readonly ForStep: "ForStep";
54
+ readonly Goal: "Goal";
55
+ readonly Job: "Job";
56
+ readonly JobStep: "JobStep";
57
+ readonly Resource: "Resource";
58
+ readonly ResourceRole: "ResourceRole";
59
+ readonly ResourceType: "ResourceType";
60
+ readonly RunnableStrategy: "RunnableStrategy";
61
+ readonly StrategyRun: "StrategyRun";
62
+ readonly StrategyThread: "StrategyThread";
63
+ readonly WhileStep: "WhileStep";
64
+ };
65
+ };
66
+ readonly ENUMS: {
67
+ readonly ResourceKind: {
68
+ readonly missing: "missing";
69
+ readonly inputPotential: "inputPotential";
70
+ readonly outputPotential: "outputPotential";
71
+ readonly materialized: "materialized";
72
+ };
73
+ readonly RunEventKind: {
74
+ readonly graph_start: "graph_start";
75
+ readonly tick: "tick";
76
+ readonly interrupt: "interrupt";
77
+ readonly graph_end: "graph_end";
78
+ };
79
+ readonly RunnableStrategyStatus: {
80
+ readonly pending: "pending";
81
+ readonly running: "running";
82
+ readonly completed: "completed";
83
+ readonly failed: "failed";
84
+ readonly cancelled: "cancelled";
85
+ };
86
+ readonly StepKind: {
87
+ readonly job: "job";
88
+ readonly branch: "branch";
89
+ readonly while: "while";
90
+ readonly for: "for";
91
+ };
92
+ };
93
+ };
94
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCZ,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { CONSTANTS as CONSTANTS_ } from "@toolproof-core/schema";
2
+ export const CONSTANTS = {
3
+ ...CONSTANTS_,
4
+ PERSISTENCE: {
5
+ BUCKETS: {
6
+ tp_resources: 'tp-resources',
7
+ tp_strategies: 'tp-strategies',
8
+ },
9
+ COLLECTIONS: {
10
+ resources: 'resources',
11
+ members: 'members',
12
+ },
13
+ },
14
+ ENGINE: {
15
+ GRAPHS: {
16
+ GraphRunStrategy: 'GraphRunStrategy',
17
+ GraphBuildStrategy: 'GraphBuildStrategy',
18
+ },
19
+ },
20
+ COSMOS: {
21
+ TYPE_Boolean: 'TYPE-Boolean',
22
+ TYPE_Natural: 'TYPE-Natural',
23
+ TYPE_ResourceType: 'TYPE-ResourceType',
24
+ TYPE_Job: 'TYPE-Job',
25
+ TYPE_Error: 'TYPE-Error',
26
+ TYPE_RawStrategy: 'TYPE-RawStrategy',
27
+ TYPE_RunnableStrategy: 'TYPE-RunnableStrategy',
28
+ TYPE_StrategyRun: 'TYPE-StrategyRun',
29
+ ROLE_Manual: 'ROLE-Manual',
30
+ ROLE_ErrorOutput: 'ROLE-ErrorOutput',
31
+ ROLE_LessThanSource: 'ROLE-LessThanSource',
32
+ ROLE_LessThanTarget: 'ROLE-LessThanTarget',
33
+ ROLE_LessThanDecision: 'ROLE-LessThanDecision',
34
+ JOB_LessThan: 'JOB-LessThan',
35
+ BOOLEAN_false: 'RESOURCE-qadnfFGjZsjpqLI0Du1d',
36
+ BOOLEAN_true: 'RESOURCE-iZX1cxZ9ImJRzty9Ob4G',
37
+ }
38
+ };
39
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,GAAG,UAAU;IACb,WAAW,EAAE;QACT,OAAO,EAAE;YACL,YAAY,EAAE,cAAc;YAC5B,aAAa,EAAE,eAAe;SACjC;QACD,WAAW,EAAE;YACT,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,SAAS;SACrB;KACJ;IACD,MAAM,EAAE;QACJ,MAAM,EAAE;YACJ,gBAAgB,EAAE,kBAAkB;YACpC,kBAAkB,EAAE,oBAAoB;SAC3C;KACJ;IACD,MAAM,EAAE;QACJ,YAAY,EAAE,cAAc;QAC5B,YAAY,EAAE,cAAc;QAC5B,iBAAiB,EAAE,mBAAmB;QACtC,QAAQ,EAAE,UAAU;QACpB,UAAU,EAAE,YAAY;QACxB,gBAAgB,EAAE,kBAAkB;QACpC,qBAAqB,EAAE,uBAAuB;QAC9C,gBAAgB,EAAE,kBAAkB;QACpC,WAAW,EAAE,aAAa;QAC1B,gBAAgB,EAAE,kBAAkB;QACpC,mBAAmB,EAAE,qBAAqB;QAC1C,mBAAmB,EAAE,qBAAqB;QAC1C,qBAAqB,EAAE,uBAAuB;QAC9C,YAAY,EAAE,cAAc;QAC5B,aAAa,EAAE,+BAA+B;QAC9C,YAAY,EAAE,+BAA+B;KAChD;CACK,CAAC"}
@@ -0,0 +1,94 @@
1
+ export declare const CONSTANTS: {
2
+ readonly PERSISTENCE: {
3
+ readonly BUCKETS: {
4
+ readonly tp_resources: "tp-resources";
5
+ readonly tp_strategies: "tp-strategies";
6
+ };
7
+ readonly COLLECTIONS: {
8
+ readonly resources: "resources";
9
+ readonly members: "members";
10
+ };
11
+ };
12
+ readonly ENGINE: {
13
+ readonly GRAPHS: {
14
+ readonly GraphRunStrategy: "GraphRunStrategy";
15
+ readonly GraphBuildStrategy: "GraphBuildStrategy";
16
+ };
17
+ };
18
+ readonly COSMOS: {
19
+ readonly TYPE_Boolean: "TYPE-Boolean";
20
+ readonly TYPE_Natural: "TYPE-Natural";
21
+ readonly TYPE_ResourceType: "TYPE-ResourceType";
22
+ readonly TYPE_Job: "TYPE-Job";
23
+ readonly TYPE_Error: "TYPE-Error";
24
+ readonly TYPE_RawStrategy: "TYPE-RawStrategy";
25
+ readonly TYPE_RunnableStrategy: "TYPE-RunnableStrategy";
26
+ readonly TYPE_StrategyRun: "TYPE-StrategyRun";
27
+ readonly ROLE_Manual: "ROLE-Manual";
28
+ readonly ROLE_ErrorOutput: "ROLE-ErrorOutput";
29
+ readonly ROLE_LessThanSource: "ROLE-LessThanSource";
30
+ readonly ROLE_LessThanTarget: "ROLE-LessThanTarget";
31
+ readonly ROLE_LessThanDecision: "ROLE-LessThanDecision";
32
+ readonly JOB_LessThan: "JOB-LessThan";
33
+ readonly BOOLEAN_false: "RESOURCE-qadnfFGjZsjpqLI0Du1d";
34
+ readonly BOOLEAN_true: "RESOURCE-iZX1cxZ9ImJRzty9Ob4G";
35
+ };
36
+ readonly IDENTIFIABLES: {
37
+ readonly PREFIXES: {
38
+ readonly BranchStepIdentity: "BRANCH_STEP-";
39
+ readonly ForStepIdentity: "FOR_STEP-";
40
+ readonly GoalIdentity: "GOAL-";
41
+ readonly JobIdentity: "JOB-";
42
+ readonly JobStepIdentity: "JOB_STEP-";
43
+ readonly ResourceIdentity: "RESOURCE-";
44
+ readonly ResourceRoleIdentity: "ROLE-";
45
+ readonly ResourceTypeIdentity: "TYPE-";
46
+ readonly RunnableStrategyIdentity: "RUNNABLE_STRATEGY-";
47
+ readonly StrategyRunIdentity: "STRATEGY_RUN-";
48
+ readonly StrategyThreadIdentity: "STRATEGY_THREAD-";
49
+ readonly WhileStepIdentity: "WHILE_STEP-";
50
+ };
51
+ readonly NAMES: {
52
+ readonly BranchStep: "BranchStep";
53
+ readonly ForStep: "ForStep";
54
+ readonly Goal: "Goal";
55
+ readonly Job: "Job";
56
+ readonly JobStep: "JobStep";
57
+ readonly Resource: "Resource";
58
+ readonly ResourceRole: "ResourceRole";
59
+ readonly ResourceType: "ResourceType";
60
+ readonly RunnableStrategy: "RunnableStrategy";
61
+ readonly StrategyRun: "StrategyRun";
62
+ readonly StrategyThread: "StrategyThread";
63
+ readonly WhileStep: "WhileStep";
64
+ };
65
+ };
66
+ readonly ENUMS: {
67
+ readonly ResourceKind: {
68
+ readonly missing: "missing";
69
+ readonly "input-potential": "input-potential";
70
+ readonly "output-potential": "output-potential";
71
+ readonly materialized: "materialized";
72
+ };
73
+ readonly RunEventKind: {
74
+ readonly graph_start: "graph_start";
75
+ readonly tick: "tick";
76
+ readonly interrupt: "interrupt";
77
+ readonly graph_end: "graph_end";
78
+ };
79
+ readonly RunnableStrategyStatus: {
80
+ readonly pending: "pending";
81
+ readonly running: "running";
82
+ readonly completed: "completed";
83
+ readonly failed: "failed";
84
+ readonly cancelled: "cancelled";
85
+ };
86
+ readonly StepKind: {
87
+ readonly job: "job";
88
+ readonly branch: "branch";
89
+ readonly while: "while";
90
+ readonly for: "for";
91
+ };
92
+ };
93
+ };
94
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/declarations/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCZ,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { CONSTANTS as CONSTANTS_ } from "@toolproof-core/schema";
2
+ export const CONSTANTS = {
3
+ ...CONSTANTS_,
4
+ PERSISTENCE: {
5
+ BUCKETS: {
6
+ tp_resources: 'tp-resources',
7
+ tp_strategies: 'tp-strategies',
8
+ },
9
+ COLLECTIONS: {
10
+ resources: 'resources',
11
+ members: 'members',
12
+ },
13
+ },
14
+ ENGINE: {
15
+ GRAPHS: {
16
+ GraphRunStrategy: 'GraphRunStrategy',
17
+ GraphBuildStrategy: 'GraphBuildStrategy',
18
+ },
19
+ },
20
+ COSMOS: {
21
+ TYPE_Boolean: 'TYPE-Boolean',
22
+ TYPE_Natural: 'TYPE-Natural',
23
+ TYPE_ResourceType: 'TYPE-ResourceType',
24
+ TYPE_Job: 'TYPE-Job',
25
+ TYPE_Error: 'TYPE-Error',
26
+ TYPE_RawStrategy: 'TYPE-RawStrategy',
27
+ TYPE_RunnableStrategy: 'TYPE-RunnableStrategy',
28
+ TYPE_StrategyRun: 'TYPE-StrategyRun',
29
+ ROLE_Manual: 'ROLE-Manual',
30
+ ROLE_ErrorOutput: 'ROLE-ErrorOutput',
31
+ ROLE_LessThanSource: 'ROLE-LessThanSource',
32
+ ROLE_LessThanTarget: 'ROLE-LessThanTarget',
33
+ ROLE_LessThanDecision: 'ROLE-LessThanDecision',
34
+ JOB_LessThan: 'JOB-LessThan',
35
+ BOOLEAN_false: 'RESOURCE-qadnfFGjZsjpqLI0Du1d',
36
+ BOOLEAN_true: 'RESOURCE-iZX1cxZ9ImJRzty9Ob4G',
37
+ }
38
+ };
39
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/declarations/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,GAAG,UAAU;IACb,WAAW,EAAE;QACT,OAAO,EAAE;YACL,YAAY,EAAE,cAAc;YAC5B,aAAa,EAAE,eAAe;SACjC;QACD,WAAW,EAAE;YACT,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,SAAS;SACrB;KACJ;IACD,MAAM,EAAE;QACJ,MAAM,EAAE;YACJ,gBAAgB,EAAE,kBAAkB;YACpC,kBAAkB,EAAE,oBAAoB;SAC3C;KACJ;IACD,MAAM,EAAE;QACJ,YAAY,EAAE,cAAc;QAC5B,YAAY,EAAE,cAAc;QAC5B,iBAAiB,EAAE,mBAAmB;QACtC,QAAQ,EAAE,UAAU;QACpB,UAAU,EAAE,YAAY;QACxB,gBAAgB,EAAE,kBAAkB;QACpC,qBAAqB,EAAE,uBAAuB;QAC9C,gBAAgB,EAAE,kBAAkB;QACpC,WAAW,EAAE,aAAa;QAC1B,gBAAgB,EAAE,kBAAkB;QACpC,mBAAmB,EAAE,qBAAqB;QAC1C,mBAAmB,EAAE,qBAAqB;QAC1C,qBAAqB,EAAE,uBAAuB;QAC9C,YAAY,EAAE,cAAc;QAC5B,aAAa,EAAE,+BAA+B;QAC9C,YAAY,EAAE,+BAA+B;KAChD;CACK,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ResourceJson, ResourceRoleIdentityJson, ResourceRoleValueJson, ResourceTypeIdentityJson } from '@toolproof-core/schema';
2
+ import { CONSTANTS } from './constants.js';
3
+ export type BucketConst = typeof CONSTANTS.PERSISTENCE.BUCKETS.tp_resources;
4
+ export type CollectionConst = keyof typeof CONSTANTS.PERSISTENCE.COLLECTIONS;
5
+ export type IdentityPrefix = keyof typeof CONSTANTS.IDENTIFIABLES.PREFIXES;
6
+ export type Role = {
7
+ identity: ResourceRoleIdentityJson;
8
+ } & ResourceRoleValueJson;
9
+ export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/declarations/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC;AAE5E,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC;AAE7E,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC;AAE3E,MAAM,MAAM,IAAI,GAAG;IAAE,QAAQ,EAAE,wBAAwB,CAAA;CAAE,GAAG,qBAAqB,CAAC;AAElF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,wBAAwB,EAAE,YAAY,EAAE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { CONSTANTS } from './constants.js';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/declarations/types.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { ResourceJson, ResourceRoleIdentityJson, ResourceRoleValueJson, ResourceTypeIdentityJson } from '@toolproof-core/schema';
2
+ import { CONSTANTS } from '../declarations/constants.js';
3
+ export type BucketConst = typeof CONSTANTS.STORAGE.BUCKETS.tp_resources;
4
+ export type CollectionConst = keyof typeof CONSTANTS.STORAGE.COLLECTIONS;
5
+ export type IdentityPrefix = keyof typeof CONSTANTS.IDENTITY_PREFIXES;
6
+ export type StepConst = keyof typeof CONSTANTS.STEPS;
7
+ export type Role = {
8
+ identity: ResourceRoleIdentityJson;
9
+ } & ResourceRoleValueJson;
10
+ export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
11
+ //# sourceMappingURL=typesTS.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typesTS.d.ts","sourceRoot":"","sources":["../../src/declarations/typesTS.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC;AAExE,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC;AAEzE,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,SAAS,CAAC,iBAAiB,CAAC;AAEtE,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,SAAS,CAAC,KAAK,CAAC;AAErD,MAAM,MAAM,IAAI,GAAG;IAAE,QAAQ,EAAE,wBAAwB,CAAA;CAAE,GAAG,qBAAqB,CAAC;AAElF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,wBAAwB,EAAE,YAAY,EAAE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { CONSTANTS } from '../declarations/constants.js';
2
+ //# sourceMappingURL=typesTS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typesTS.js","sourceRoot":"","sources":["../../src/declarations/typesTS.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { BranchStepIdentityJson, ForStepIdentityJson, GoalIdentityJson, JobIdentityJson, JobStepIdentityJson, ResourceIdentityJson, ResourceRoleIdentityJson, ResourceTypeIdentityJson, RunnableStrategyIdentityJson, StrategyRunIdentityJson, StrategyThreadIdentityJson, WhileStepIdentityJson } from '@toolproof-core/schema';
2
+ import type { ResourceMap, IdentityPrefix } from '../types/types.js';
3
+ import { CONSTANTS } from '../constants/constants.js';
4
+ export type StepKind = keyof typeof CONSTANTS.ENUMS.StepKind;
5
+ declare const STEP_KIND_TO_IDENTITY_PREFIX_KEY: {
6
+ readonly job: "JobStepIdentity";
7
+ readonly branch: "BranchStepIdentity";
8
+ readonly while: "WhileStepIdentity";
9
+ readonly for: "ForStepIdentity";
10
+ };
11
+ type StepIdentityPrefixKey = (typeof STEP_KIND_TO_IDENTITY_PREFIX_KEY)[StepKind];
12
+ type IdentityJsonByPrefixKey = {
13
+ ResourceTypeIdentity: ResourceTypeIdentityJson;
14
+ ResourceRoleIdentity: ResourceRoleIdentityJson;
15
+ ResourceIdentity: ResourceIdentityJson;
16
+ JobIdentity: JobIdentityJson;
17
+ JobStepIdentity: JobStepIdentityJson;
18
+ BranchStepIdentity: BranchStepIdentityJson;
19
+ WhileStepIdentity: WhileStepIdentityJson;
20
+ ForStepIdentity: ForStepIdentityJson;
21
+ StrategyThreadIdentity: StrategyThreadIdentityJson;
22
+ RunnableStrategyIdentity: RunnableStrategyIdentityJson;
23
+ StrategyRunIdentity: StrategyRunIdentityJson;
24
+ GoalIdentity: GoalIdentityJson;
25
+ };
26
+ export type NewIdentity<T extends IdentityPrefix = IdentityPrefix> = T extends keyof IdentityJsonByPrefixKey ? IdentityJsonByPrefixKey[T] : `${(typeof CONSTANTS.IDENTIFIABLES.PREFIXES)[T]}${string}`;
27
+ export declare function getNewIdentity<T extends IdentityPrefix>(identifiable: T): NewIdentity<T>;
28
+ export declare function getNewStepIdentityPrefix<K extends StepKind>(kind: K): (typeof CONSTANTS.IDENTIFIABLES.PREFIXES)[StepIdentityPrefixKey];
29
+ type StepIdentityForKind<K extends StepKind> = IdentityJsonByPrefixKey[(typeof STEP_KIND_TO_IDENTITY_PREFIX_KEY)[K]];
30
+ export declare function getNewStepIdentity<K extends StepKind>(kind: K): Promise<StepIdentityForKind<K>>;
31
+ export declare function listResources(resourceTypeHandles: ResourceTypeIdentityJson[]): Promise<ResourceMap>;
32
+ export {};
33
+ //# sourceMappingURL=firebaseAdminHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseAdminHelpers.d.ts","sourceRoot":"","sources":["../../src/firebase/firebaseAdminHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EAEnB,oBAAoB,EACpB,wBAAwB,EACxB,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,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,OAAO,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,CAGtI;AAED,KAAK,mBAAmB,CAAC,CAAC,SAAS,QAAQ,IAAI,uBAAuB,CAAC,CAAC,OAAO,gCAAgC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAErH,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAGrG;AAED,wBAAsB,aAAa,CAC/B,mBAAmB,EAAE,wBAAwB,EAAE,GAChD,OAAO,CAAC,WAAW,CAAC,CAgHtB"}
@@ -0,0 +1,150 @@
1
+ import { CONSTANTS } from '../constants/constants.js';
2
+ import { dbAdmin, storageAdmin } from "./firebaseAdminInit.js";
3
+ const STEP_KIND_TO_IDENTITY_PREFIX_KEY = {
4
+ job: 'JobStepIdentity',
5
+ branch: 'BranchStepIdentity',
6
+ while: 'WhileStepIdentity',
7
+ for: 'ForStepIdentity',
8
+ };
9
+ export function getNewIdentity(identifiable) {
10
+ const prefix = CONSTANTS.IDENTIFIABLES.PREFIXES[identifiable];
11
+ const docRef = dbAdmin
12
+ .collection(CONSTANTS.PERSISTENCE.COLLECTIONS.resources)
13
+ .doc(identifiable)
14
+ .collection(CONSTANTS.PERSISTENCE.COLLECTIONS.members)
15
+ .doc();
16
+ return (prefix + docRef.id);
17
+ }
18
+ export function getNewStepIdentityPrefix(kind) {
19
+ const key = STEP_KIND_TO_IDENTITY_PREFIX_KEY[kind];
20
+ return CONSTANTS.IDENTIFIABLES.PREFIXES[key];
21
+ }
22
+ export async function getNewStepIdentity(kind) {
23
+ const key = STEP_KIND_TO_IDENTITY_PREFIX_KEY[kind];
24
+ return getNewIdentity(key);
25
+ }
26
+ export async function listResources(resourceTypeHandles) {
27
+ const bucket_resources = storageAdmin.bucket(CONSTANTS.PERSISTENCE.BUCKETS.tp_resources);
28
+ const bucket_strategies = storageAdmin.bucket(CONSTANTS.PERSISTENCE.BUCKETS.tp_strategies);
29
+ async function fetchFilesUnder(resourceTypeHandle) {
30
+ const bucket = resourceTypeHandle === CONSTANTS.COSMOS.TYPE_RunnableStrategy
31
+ ? bucket_strategies
32
+ : bucket_resources;
33
+ const prefix = `${resourceTypeHandle}/`;
34
+ const [found] = await bucket.getFiles({ prefix });
35
+ const files = found.filter(f => {
36
+ const name = f.name || '';
37
+ if (!name || name.endsWith('/'))
38
+ return false;
39
+ return true;
40
+ });
41
+ if (!files.length)
42
+ return [];
43
+ const items = await Promise.all(files.map(async (file) => {
44
+ try {
45
+ const [buf] = await file.download();
46
+ const meta = file.metadata || (await file.getMetadata())[0];
47
+ const data = JSON.parse(buf.toString('utf8'));
48
+ return { data, meta, name: file.name };
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }));
54
+ return items.filter(Boolean);
55
+ }
56
+ const entries = await Promise.all(resourceTypeHandles.map(async (resourceTypeHandle) => {
57
+ const rows = await fetchFilesUnder(resourceTypeHandle);
58
+ const items = rows.map(({ data, meta, name }) => {
59
+ const flat = meta?.metadata ?? {};
60
+ // Reconstruct nested object from flattened keys (dot and array index notation)
61
+ const root = {};
62
+ for (const [k, vRaw] of Object.entries(flat)) {
63
+ if (typeof vRaw !== 'string')
64
+ continue; // GCS should store only strings
65
+ const vStr = vRaw.trim();
66
+ // Attempt JSON parse for non-simple primitives
67
+ let value = vStr;
68
+ if ((vStr.startsWith('{') && vStr.endsWith('}')) || (vStr.startsWith('[') && vStr.endsWith(']'))) {
69
+ try {
70
+ value = JSON.parse(vStr);
71
+ }
72
+ catch {
73
+ value = vStr;
74
+ }
75
+ }
76
+ // Split by '.' while preserving array indices
77
+ const segments = k.split('.');
78
+ let cursor = root;
79
+ for (const [i, seg] of segments.entries()) {
80
+ const arrIdxMatch = seg.match(/^(.*)\[(\d+)\]$/);
81
+ if (arrIdxMatch) {
82
+ const base = arrIdxMatch[1];
83
+ const idxStr = arrIdxMatch[2];
84
+ if (base === undefined || idxStr === undefined)
85
+ continue;
86
+ const idx = parseInt(idxStr, 10);
87
+ if (!cursor[base])
88
+ cursor[base] = [];
89
+ if (!Array.isArray(cursor[base]))
90
+ cursor[base] = [];
91
+ while (cursor[base].length <= idx)
92
+ cursor[base].push(undefined);
93
+ if (i === segments.length - 1) {
94
+ cursor[base][idx] = value;
95
+ }
96
+ else {
97
+ if (!cursor[base][idx])
98
+ cursor[base][idx] = {};
99
+ cursor = cursor[base][idx];
100
+ }
101
+ }
102
+ else {
103
+ if (i === segments.length - 1) {
104
+ cursor[seg] = value;
105
+ }
106
+ else {
107
+ if (!cursor[seg] || typeof cursor[seg] !== 'object')
108
+ cursor[seg] = {};
109
+ cursor = cursor[seg];
110
+ }
111
+ }
112
+ }
113
+ }
114
+ const identity = root.identity;
115
+ // const resourceTypeHandle = root.resourceTypeHandle; // we already have this
116
+ const resourceRoleHandle = root.creationContext.resourceRoleHandle;
117
+ const jobStepHandle = root.creationContext.jobStepHandle;
118
+ const stepKind = root.stepKind;
119
+ const path = root.path;
120
+ const timestamp = root.timestamp;
121
+ const missing = [
122
+ ['identity', identity],
123
+ ['resourceRoleHandle', resourceRoleHandle],
124
+ ['jobStepHandle', jobStepHandle],
125
+ ['stepKind', stepKind],
126
+ ['timestamp', timestamp],
127
+ ['path', path],
128
+ ].filter(([_, v]) => typeof v !== 'string' || v.length === 0);
129
+ if (missing.length) {
130
+ const keys = missing.map(([k]) => k).join(', ');
131
+ throw new Error(`Missing required metadata keys [${keys}] for resource file: ${name}`);
132
+ }
133
+ return {
134
+ identity,
135
+ resourceTypeHandle,
136
+ creationContext: {
137
+ resourceRoleHandle,
138
+ jobStepHandle,
139
+ },
140
+ stepKind: stepKind,
141
+ path: path,
142
+ timestamp: timestamp,
143
+ nucleus: data,
144
+ };
145
+ });
146
+ return [resourceTypeHandle, items];
147
+ }));
148
+ return Object.fromEntries(entries);
149
+ }
150
+ //# sourceMappingURL=firebaseAdminHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseAdminHelpers.js","sourceRoot":"","sources":["../../src/firebase/firebaseAdminHelpers.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAI/D,MAAM,gCAAgC,GAAG;IACrC,GAAG,EAAE,iBAAiB;IACtB,MAAM,EAAE,oBAAoB;IAC5B,KAAK,EAAE,mBAAmB;IAC1B,GAAG,EAAE,iBAAiB;CAChB,CAAC;AAwBX,MAAM,UAAU,cAAc,CAA2B,YAAe;IACpE,MAAM,MAAM,GAAG,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,OAAO;SACjB,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC;SACvD,GAAG,CAAC,YAAY,CAAC;SACjB,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC;SACrD,GAAG,EAAE,CAAC;IACX,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAmB,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAqB,IAAO;IAChE,MAAM,GAAG,GAAG,gCAAgC,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC;AAID,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAqB,IAAO;IAChE,MAAM,GAAG,GAAG,gCAAgC,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,cAAc,CAAC,GAAG,CAA2B,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAC/B,mBAA+C;IAE/C,MAAM,gB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AC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAY,CAAC,MAAM,KAAK,CAAC,CAAwC,CAAC;YAEjH,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBACjB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAChD,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,wBAAwB,IAAI,EAAE,CAAC,CAAC;YAC3F,CAAC;YAED,OAAO;gBACH,QAAQ;gBACR,kBAAkB;gBAClB,eAAe,EAAE;oBACb,kBAAkB;oBAClB,aAAa;iBAChB;gBACD,QAAQ,EAAE,QAAkB;gBAC5B,IAAI,EAAE,IAAc;gBACpB,SAAS,EAAE,SAAmB;gBAC9B,OAAO,EAAE,IAAW;aACI,CAAC;QACjC,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,kBAAkB,EAAE,KAAK,CAAU,CAAC;IAChD,CAAC,CAAC,CACL,CAAC;IACF,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAgB,CAAC;AACtD,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const dbAdmin: FirebaseFirestore.Firestore;
2
+ declare const storageAdmin: import("firebase-admin/storage").Storage;
3
+ export { dbAdmin, storageAdmin };
4
+ //# sourceMappingURL=firebaseAdminInit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseAdminInit.d.ts","sourceRoot":"","sources":["../../src/firebase/firebaseAdminInit.ts"],"names":[],"mappings":"AAkCA,QAAA,MAAM,OAAO,6BAAoB,CAAC;AAClC,QAAA,MAAM,YAAY,0CAAkB,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { getApp, getApps, initializeApp, applicationDefault, cert } from 'firebase-admin/app';
2
+ import { getFirestore } from 'firebase-admin/firestore';
3
+ import { getStorage } from 'firebase-admin/storage';
4
+ import { existsSync, readFileSync } from 'fs';
5
+ import path from 'path';
6
+ // Resolve credentials: prefer GOOGLE_APPLICATION_CREDENTIALS, fallback to local gcp-key.json, else ADC
7
+ function resolveCredential() {
8
+ const jsonString = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON;
9
+ const envPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
10
+ const localKeyPath = path.join(process.cwd(), 'gcp-key.json');
11
+ try {
12
+ if (jsonString) {
13
+ const json = JSON.parse(jsonString);
14
+ return cert(json);
15
+ }
16
+ if (envPath && existsSync(envPath)) {
17
+ const json = JSON.parse(readFileSync(envPath, 'utf8'));
18
+ return cert(json);
19
+ }
20
+ if (existsSync(localKeyPath)) {
21
+ const json = JSON.parse(readFileSync(localKeyPath, 'utf8'));
22
+ return cert(json);
23
+ }
24
+ }
25
+ catch {
26
+ // fall through to ADC
27
+ }
28
+ return applicationDefault();
29
+ }
30
+ const app = getApps().length ? getApp() : initializeApp({
31
+ credential: resolveCredential(),
32
+ projectId: "toolproof-563fe",
33
+ });
34
+ const dbAdmin = getFirestore(app);
35
+ const storageAdmin = getStorage(app);
36
+ export { dbAdmin, storageAdmin };
37
+ //# sourceMappingURL=firebaseAdminInit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseAdminInit.js","sourceRoot":"","sources":["../../src/firebase/firebaseAdminInit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,uGAAuG;AACvG,SAA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YAAY,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * as CONSTANTS from './constants/constants.js';
2
+ export * as TYPES_TS from './types/types.js';
3
+ export * from './firebase/firebaseAdminHelpers.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,cAAc,oCAAoC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * as CONSTANTS from './constants/constants.js';
2
+ export * as TYPES_TS from './types/types.js';
3
+ export * from './firebase/firebaseAdminHelpers.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,cAAc,oCAAoC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ResourceJson, ResourceRoleIdentityJson, ResourceRoleValueJson, ResourceTypeIdentityJson } from '@toolproof-core/schema';
2
+ import { CONSTANTS } from '../constants/constants.js';
3
+ export type BucketConst = typeof CONSTANTS.PERSISTENCE.BUCKETS.tp_resources;
4
+ export type CollectionConst = keyof typeof CONSTANTS.PERSISTENCE.COLLECTIONS;
5
+ export type IdentityPrefix = keyof typeof CONSTANTS.IDENTIFIABLES.PREFIXES;
6
+ export type Role = {
7
+ identity: ResourceRoleIdentityJson;
8
+ } & ResourceRoleValueJson;
9
+ export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC;AAE5E,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC;AAE7E,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC;AAE3E,MAAM,MAAM,IAAI,GAAG;IAAE,QAAQ,EAAE,wBAAwB,CAAA;CAAE,GAAG,qBAAqB,CAAC;AAElF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,wBAAwB,EAAE,YAAY,EAAE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { CONSTANTS } from '../constants/constants.js';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@toolproof-core/lib",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./constants": {
17
+ "types": "./dist/declarations/constants.d.ts",
18
+ "import": "./dist/declarations/constants.js"
19
+ },
20
+ "./typesTS": {
21
+ "types": "./dist/declarations/typesTS.d.ts",
22
+ "import": "./dist/declarations/typesTS.js"
23
+ }
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^22.0.0"
27
+ },
28
+ "dependencies": {
29
+ "firebase-admin": "^13.7.0",
30
+ "@toolproof-core/schema": "1.0.8"
31
+ },
32
+ "scripts": {
33
+ "test": "echo \"Error: no test specified\" && exit 1",
34
+ "build": "tsc -b"
35
+ }
36
+ }
@@ -0,0 +1,39 @@
1
+ import { CONSTANTS as CONSTANTS_ } from "@toolproof-core/schema";
2
+
3
+ export const CONSTANTS = {
4
+ ...CONSTANTS_,
5
+ PERSISTENCE: {
6
+ BUCKETS: {
7
+ tp_resources: 'tp-resources',
8
+ tp_strategies: 'tp-strategies',
9
+ },
10
+ COLLECTIONS: {
11
+ resources: 'resources',
12
+ members: 'members',
13
+ },
14
+ },
15
+ ENGINE: {
16
+ GRAPHS: {
17
+ GraphRunStrategy: 'GraphRunStrategy',
18
+ GraphBuildStrategy: 'GraphBuildStrategy',
19
+ },
20
+ },
21
+ COSMOS: {
22
+ TYPE_Boolean: 'TYPE-Boolean',
23
+ TYPE_Natural: 'TYPE-Natural',
24
+ TYPE_ResourceType: 'TYPE-ResourceType',
25
+ TYPE_Job: 'TYPE-Job',
26
+ TYPE_Error: 'TYPE-Error',
27
+ TYPE_RawStrategy: 'TYPE-RawStrategy',
28
+ TYPE_RunnableStrategy: 'TYPE-RunnableStrategy',
29
+ TYPE_StrategyRun: 'TYPE-StrategyRun',
30
+ ROLE_Manual: 'ROLE-Manual',
31
+ ROLE_ErrorOutput: 'ROLE-ErrorOutput',
32
+ ROLE_LessThanSource: 'ROLE-LessThanSource',
33
+ ROLE_LessThanTarget: 'ROLE-LessThanTarget',
34
+ ROLE_LessThanDecision: 'ROLE-LessThanDecision',
35
+ JOB_LessThan: 'JOB-LessThan',
36
+ BOOLEAN_false: 'RESOURCE-qadnfFGjZsjpqLI0Du1d',
37
+ BOOLEAN_true: 'RESOURCE-iZX1cxZ9ImJRzty9Ob4G',
38
+ }
39
+ } as const;
@@ -0,0 +1,189 @@
1
+ import type {
2
+ BranchStepIdentityJson,
3
+ ForStepIdentityJson,
4
+ GoalIdentityJson,
5
+ JobIdentityJson,
6
+ JobStepIdentityJson,
7
+ ResourceJson,
8
+ ResourceIdentityJson,
9
+ ResourceRoleIdentityJson,
10
+ ResourceTypeIdentityJson,
11
+ RunnableStrategyIdentityJson,
12
+ StrategyRunIdentityJson,
13
+ StrategyThreadIdentityJson,
14
+ WhileStepIdentityJson,
15
+ } from '@toolproof-core/schema';
16
+ import type { ResourceMap, IdentityPrefix } from '../types/types.js';
17
+ import { CONSTANTS } from '../constants/constants.js';
18
+ import { dbAdmin, storageAdmin } from "./firebaseAdminInit.js";
19
+
20
+ export type StepKind = keyof typeof CONSTANTS.ENUMS.StepKind;
21
+
22
+ const STEP_KIND_TO_IDENTITY_PREFIX_KEY = {
23
+ job: 'JobStepIdentity',
24
+ branch: 'BranchStepIdentity',
25
+ while: 'WhileStepIdentity',
26
+ for: 'ForStepIdentity',
27
+ } as const;
28
+
29
+ type StepIdentityPrefixKey = (typeof STEP_KIND_TO_IDENTITY_PREFIX_KEY)[StepKind];
30
+
31
+ type IdentityJsonByPrefixKey = {
32
+ ResourceTypeIdentity: ResourceTypeIdentityJson;
33
+ ResourceRoleIdentity: ResourceRoleIdentityJson;
34
+ ResourceIdentity: ResourceIdentityJson;
35
+ JobIdentity: JobIdentityJson;
36
+ JobStepIdentity: JobStepIdentityJson;
37
+ BranchStepIdentity: BranchStepIdentityJson;
38
+ WhileStepIdentity: WhileStepIdentityJson;
39
+ ForStepIdentity: ForStepIdentityJson;
40
+ StrategyThreadIdentity: StrategyThreadIdentityJson;
41
+ RunnableStrategyIdentity: RunnableStrategyIdentityJson;
42
+ StrategyRunIdentity: StrategyRunIdentityJson;
43
+ GoalIdentity: GoalIdentityJson;
44
+ };
45
+
46
+ export type NewIdentity<T extends IdentityPrefix = IdentityPrefix> =
47
+ T extends keyof IdentityJsonByPrefixKey
48
+ ? IdentityJsonByPrefixKey[T]
49
+ : `${(typeof CONSTANTS.IDENTIFIABLES.PREFIXES)[T]}${string}`;
50
+
51
+ export function getNewIdentity<T extends IdentityPrefix>(identifiable: T): NewIdentity<T> {
52
+ const prefix = CONSTANTS.IDENTIFIABLES.PREFIXES[identifiable];
53
+ const docRef = dbAdmin
54
+ .collection(CONSTANTS.PERSISTENCE.COLLECTIONS.resources)
55
+ .doc(identifiable)
56
+ .collection(CONSTANTS.PERSISTENCE.COLLECTIONS.members)
57
+ .doc();
58
+ return (prefix + docRef.id) as NewIdentity<T>;
59
+ }
60
+
61
+ export function getNewStepIdentityPrefix<K extends StepKind>(kind: K): (typeof CONSTANTS.IDENTIFIABLES.PREFIXES)[StepIdentityPrefixKey] {
62
+ const key = STEP_KIND_TO_IDENTITY_PREFIX_KEY[kind];
63
+ return CONSTANTS.IDENTIFIABLES.PREFIXES[key];
64
+ }
65
+
66
+ type StepIdentityForKind<K extends StepKind> = IdentityJsonByPrefixKey[(typeof STEP_KIND_TO_IDENTITY_PREFIX_KEY)[K]];
67
+
68
+ export async function getNewStepIdentity<K extends StepKind>(kind: K): Promise<StepIdentityForKind<K>> {
69
+ const key = STEP_KIND_TO_IDENTITY_PREFIX_KEY[kind];
70
+ return getNewIdentity(key) as StepIdentityForKind<K>;
71
+ }
72
+
73
+ export async function listResources(
74
+ resourceTypeHandles: ResourceTypeIdentityJson[]
75
+ ): Promise<ResourceMap> {
76
+ const bucket_resources = storageAdmin.bucket(CONSTANTS.PERSISTENCE.BUCKETS.tp_resources);
77
+ const bucket_strategies = storageAdmin.bucket(CONSTANTS.PERSISTENCE.BUCKETS.tp_strategies);
78
+
79
+ async function fetchFilesUnder(resourceTypeHandle: ResourceTypeIdentityJson): Promise<Array<{ data: unknown; meta: any; name: string }>> {
80
+ const bucket = resourceTypeHandle === CONSTANTS.COSMOS.TYPE_RunnableStrategy
81
+ ? bucket_strategies
82
+ : bucket_resources;
83
+ const prefix = `${resourceTypeHandle}/`;
84
+ const [found] = await bucket.getFiles({ prefix });
85
+ const files = found.filter(f => {
86
+ const name = f.name || '';
87
+ if (!name || name.endsWith('/')) return false;
88
+ return true;
89
+ });
90
+ if (!files.length) return [];
91
+ const items = await Promise.all(files.map(async (file) => {
92
+ try {
93
+ const [buf] = await file.download();
94
+ const meta = file.metadata || (await file.getMetadata())[0];
95
+ const data = JSON.parse(buf.toString('utf8')) as unknown;
96
+ return { data, meta, name: file.name };
97
+ } catch {
98
+ return null as unknown as { data: unknown; meta: any; name: string };
99
+ }
100
+ }));
101
+ return items.filter(Boolean) as Array<{ data: unknown; meta: any; name: string }>;
102
+ }
103
+
104
+ const entries = await Promise.all(
105
+ resourceTypeHandles.map(async (resourceTypeHandle) => {
106
+ const rows = await fetchFilesUnder(resourceTypeHandle);
107
+ const items: ResourceJson[] = rows.map(({ data, meta, name }) => {
108
+ const flat = meta?.metadata ?? {};
109
+ // Reconstruct nested object from flattened keys (dot and array index notation)
110
+ const root: any = {};
111
+ for (const [k, vRaw] of Object.entries(flat)) {
112
+ if (typeof vRaw !== 'string') continue; // GCS should store only strings
113
+ const vStr = vRaw.trim();
114
+ // Attempt JSON parse for non-simple primitives
115
+ let value: any = vStr;
116
+ if ((vStr.startsWith('{') && vStr.endsWith('}')) || (vStr.startsWith('[') && vStr.endsWith(']'))) {
117
+ try { value = JSON.parse(vStr); } catch { value = vStr; }
118
+ }
119
+ // Split by '.' while preserving array indices
120
+ const segments = k.split('.');
121
+ let cursor = root;
122
+ for (const [i, seg] of segments.entries()) {
123
+ const arrIdxMatch = seg.match(/^(.*)\[(\d+)\]$/);
124
+ if (arrIdxMatch) {
125
+ const base = arrIdxMatch[1];
126
+ const idxStr = arrIdxMatch[2];
127
+ if (base === undefined || idxStr === undefined) continue;
128
+ const idx = parseInt(idxStr, 10);
129
+ if (!cursor[base]) cursor[base] = [];
130
+ if (!Array.isArray(cursor[base])) cursor[base] = [];
131
+ while (cursor[base].length <= idx) cursor[base].push(undefined);
132
+ if (i === segments.length - 1) {
133
+ cursor[base][idx] = value;
134
+ } else {
135
+ if (!cursor[base][idx]) cursor[base][idx] = {};
136
+ cursor = cursor[base][idx];
137
+ }
138
+ } else {
139
+ if (i === segments.length - 1) {
140
+ cursor[seg] = value;
141
+ } else {
142
+ if (!cursor[seg] || typeof cursor[seg] !== 'object') cursor[seg] = {};
143
+ cursor = cursor[seg];
144
+ }
145
+ }
146
+ }
147
+ }
148
+ const identity = root.identity;
149
+ // const resourceTypeHandle = root.resourceTypeHandle; // we already have this
150
+ const resourceRoleHandle = root.creationContext.resourceRoleHandle;
151
+ const jobStepHandle = root.creationContext.jobStepHandle;
152
+ const stepKind = root.stepKind;
153
+ const path = root.path;
154
+ const timestamp = root.timestamp;
155
+
156
+ const missing = [
157
+ ['identity', identity],
158
+ ['resourceRoleHandle', resourceRoleHandle],
159
+ ['jobStepHandle', jobStepHandle],
160
+ ['stepKind', stepKind],
161
+ ['timestamp', timestamp],
162
+ ['path', path],
163
+ ].filter(([_, v]) => typeof v !== 'string' || (v as string).length === 0) as Array<[string, string | undefined]>;
164
+
165
+ if (missing.length) {
166
+ const keys = missing.map(([k]) => k).join(', ');
167
+ throw new Error(`Missing required metadata keys [${keys}] for resource file: ${name}`);
168
+ }
169
+
170
+ return {
171
+ identity,
172
+ resourceTypeHandle,
173
+ creationContext: {
174
+ resourceRoleHandle,
175
+ jobStepHandle,
176
+ },
177
+ stepKind: stepKind as string,
178
+ path: path as string,
179
+ timestamp: timestamp as string,
180
+ nucleus: data as any,
181
+ } as unknown as ResourceJson;
182
+ });
183
+ return [resourceTypeHandle, items] as const;
184
+ })
185
+ );
186
+ return Object.fromEntries(entries) as ResourceMap;
187
+ }
188
+
189
+
@@ -0,0 +1,38 @@
1
+ import { getApp, getApps, initializeApp, applicationDefault, cert } from 'firebase-admin/app';
2
+ import { getFirestore } from 'firebase-admin/firestore';
3
+ import { getStorage } from 'firebase-admin/storage';
4
+ import { existsSync, readFileSync } from 'fs';
5
+ import path from 'path';
6
+
7
+ // Resolve credentials: prefer GOOGLE_APPLICATION_CREDENTIALS, fallback to local gcp-key.json, else ADC
8
+ function resolveCredential() {
9
+ const jsonString = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON;
10
+ const envPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
11
+ const localKeyPath = path.join(process.cwd(), 'gcp-key.json');
12
+ try {
13
+ if (jsonString) {
14
+ const json = JSON.parse(jsonString);
15
+ return cert(json);
16
+ }
17
+ if (envPath && existsSync(envPath)) {
18
+ const json = JSON.parse(readFileSync(envPath, 'utf8'));
19
+ return cert(json);
20
+ }
21
+ if (existsSync(localKeyPath)) {
22
+ const json = JSON.parse(readFileSync(localKeyPath, 'utf8'));
23
+ return cert(json);
24
+ }
25
+ } catch {
26
+ // fall through to ADC
27
+ }
28
+ return applicationDefault();
29
+ }
30
+
31
+ const app = getApps().length ? getApp() : initializeApp({
32
+ credential: resolveCredential(),
33
+ projectId: "toolproof-563fe",
34
+ });
35
+ const dbAdmin = getFirestore(app);
36
+ const storageAdmin = getStorage(app);
37
+
38
+ export { dbAdmin, storageAdmin };
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * as CONSTANTS from './constants/constants.js';
2
+ export * as TYPES_TS from './types/types.js';
3
+ export * from './firebase/firebaseAdminHelpers.js';
@@ -0,0 +1,17 @@
1
+ import type {
2
+ ResourceJson,
3
+ ResourceRoleIdentityJson,
4
+ ResourceRoleValueJson,
5
+ ResourceTypeIdentityJson,
6
+ } from '@toolproof-core/schema';
7
+ import { CONSTANTS } from '../constants/constants.js';
8
+
9
+ export type BucketConst = typeof CONSTANTS.PERSISTENCE.BUCKETS.tp_resources;
10
+
11
+ export type CollectionConst = keyof typeof CONSTANTS.PERSISTENCE.COLLECTIONS;
12
+
13
+ export type IdentityPrefix = keyof typeof CONSTANTS.IDENTIFIABLES.PREFIXES;
14
+
15
+ export type Role = { identity: ResourceRoleIdentityJson } & ResourceRoleValueJson;
16
+
17
+ export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist",
6
+ "types": ["node"]
7
+ },
8
+ "include": [
9
+ "src"
10
+ ],
11
+ "exclude": [
12
+ "dist",
13
+ "node_modules"
14
+ ]
15
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/index.ts","./src/constants/constants.ts","./src/firebase/firebaseadminhelpers.ts","./src/firebase/firebaseadmininit.ts","./src/types/types.ts"],"version":"5.9.3"}