@adaptic/backend-legacy 0.0.1057 → 0.0.1059

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 (114) hide show
  1. package/auth/authorization-map.cjs +306 -0
  2. package/auth/authorization-map.d.ts +143 -0
  3. package/auth/cortex-auth-checker.cjs +172 -0
  4. package/auth/cortex-auth-checker.d.ts +114 -0
  5. package/auth/credential-fields.cjs +51 -0
  6. package/auth/credential-fields.d.ts +19 -0
  7. package/auth/credential-redaction.cjs +134 -0
  8. package/auth/credential-redaction.d.ts +60 -0
  9. package/auth/graphql-auth-shadow.cjs +317 -0
  10. package/auth/graphql-auth-shadow.d.ts +194 -0
  11. package/auth/membership-write-authority.cjs +131 -0
  12. package/auth/membership-write-authority.d.ts +110 -0
  13. package/auth/mutation-authorization.cjs +376 -0
  14. package/auth/mutation-authorization.d.ts +261 -0
  15. package/auth/nested-write-inspector.cjs +189 -0
  16. package/auth/nested-write-inspector.d.ts +94 -0
  17. package/auth/nested-write-policy.cjs +189 -0
  18. package/auth/nested-write-policy.d.ts +99 -0
  19. package/auth/service-token.cjs +339 -0
  20. package/auth/service-token.d.ts +106 -0
  21. package/auth/tenancy-scope.cjs +736 -0
  22. package/auth/tenancy-scope.d.ts +347 -0
  23. package/auth/token-verifier.cjs +451 -0
  24. package/auth/token-verifier.d.ts +153 -0
  25. package/auth/totp.cjs +265 -0
  26. package/auth/totp.d.ts +111 -0
  27. package/auth/user-write-content.cjs +116 -0
  28. package/auth/user-write-content.d.ts +47 -0
  29. package/auth/ws-auth-context.cjs +75 -0
  30. package/auth/ws-auth-context.d.ts +69 -0
  31. package/config/jwtConfig.cjs +57 -0
  32. package/config/jwtConfig.d.ts +16 -0
  33. package/config/metrics.cjs +356 -0
  34. package/config/metrics.d.ts +128 -0
  35. package/config/persisted-queries.cjs +122 -0
  36. package/config/persisted-queries.d.ts +40 -0
  37. package/config/server-only-models.cjs +166 -0
  38. package/config/server-only-models.d.ts +89 -0
  39. package/config/tracing.d.ts +24 -0
  40. package/esm/auth/service-token.d.ts +12 -0
  41. package/esm/auth/service-token.mjs +27 -5
  42. package/esm/config/jwtConfig.mjs +5 -1
  43. package/generated/typegraphql-prisma/enhance.cjs +3 -3
  44. package/generated/typegraphql-prisma/index.cjs +6 -6
  45. package/generated/typegraphql-prisma/resolvers/crud/args.index.cjs +95 -95
  46. package/generated/typegraphql-prisma/resolvers/outputs/index.cjs +1 -1
  47. package/generated/typegraphql-prisma/resolvers/relations/args.index.cjs +32 -32
  48. package/middleware/audit-log-write-redaction.cjs +143 -0
  49. package/middleware/audit-log-write-redaction.d.ts +82 -0
  50. package/middleware/audit-logger.cjs +378 -0
  51. package/middleware/audit-logger.d.ts +158 -0
  52. package/middleware/audit-payload-guard.cjs +107 -0
  53. package/middleware/audit-payload-guard.d.ts +85 -0
  54. package/middleware/auth.cjs +66 -0
  55. package/middleware/auth.d.ts +41 -0
  56. package/middleware/credential-field-guard.cjs +514 -0
  57. package/middleware/credential-field-guard.d.ts +173 -0
  58. package/middleware/generated-type-names.cjs +77 -0
  59. package/middleware/generated-type-names.d.ts +44 -0
  60. package/middleware/graphql-validation-plugin.cjs +310 -0
  61. package/middleware/graphql-validation-plugin.d.ts +98 -0
  62. package/middleware/guard-log-throttle.cjs +89 -0
  63. package/middleware/guard-log-throttle.d.ts +80 -0
  64. package/middleware/index.cjs +57 -0
  65. package/middleware/index.d.ts +14 -0
  66. package/middleware/input-validator.cjs +220 -0
  67. package/middleware/input-validator.d.ts +63 -0
  68. package/middleware/mandate-version-validation.cjs +131 -0
  69. package/middleware/mandate-version-validation.d.ts +41 -0
  70. package/middleware/mutation-account-facts.cjs +223 -0
  71. package/middleware/mutation-account-facts.d.ts +143 -0
  72. package/middleware/mutation-auth-guard.cjs +536 -0
  73. package/middleware/mutation-auth-guard.d.ts +100 -0
  74. package/middleware/mutation-membership-facts.cjs +276 -0
  75. package/middleware/mutation-membership-facts.d.ts +133 -0
  76. package/middleware/mutation-tenant-facts.cjs +132 -0
  77. package/middleware/mutation-tenant-facts.d.ts +81 -0
  78. package/middleware/query-complexity.cjs +182 -0
  79. package/middleware/query-complexity.d.ts +56 -0
  80. package/middleware/rate-limiter.cjs +223 -0
  81. package/middleware/rate-limiter.d.ts +93 -0
  82. package/middleware/rate-tier.cjs +111 -0
  83. package/middleware/rate-tier.d.ts +56 -0
  84. package/middleware/soft-delete.cjs +175 -0
  85. package/middleware/soft-delete.d.ts +146 -0
  86. package/middleware/tenancy-scoping.cjs +229 -0
  87. package/middleware/tenancy-scoping.d.ts +67 -0
  88. package/middleware/trading-policy-audit.cjs +353 -0
  89. package/middleware/trading-policy-audit.d.ts +184 -0
  90. package/middleware/types.cjs +17 -0
  91. package/middleware/types.d.ts +87 -0
  92. package/middleware/validation-examples.cjs +398 -0
  93. package/middleware/validation-examples.d.ts +76 -0
  94. package/package.json +10 -2
  95. package/readers/index.cjs +15 -0
  96. package/readers/index.d.ts +10 -0
  97. package/readers/intraday-lane-prefs.cjs +76 -0
  98. package/readers/intraday-lane-prefs.d.ts +45 -0
  99. package/esm/config/__tests__/server-only-surface.harness.d.ts +0 -12
  100. package/esm/config/__tests__/server-only-surface.harness.mjs +0 -41
  101. package/esm/middleware/__tests__/audit-log-write-redaction.harness.d.ts +0 -144
  102. package/esm/middleware/__tests__/audit-log-write-redaction.harness.mjs +0 -920
  103. package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts +0 -55
  104. package/esm/middleware/__tests__/credential-field-coverage.harness.mjs +0 -440
  105. package/esm/middleware/__tests__/credential-field-guard.harness.d.ts +0 -34
  106. package/esm/middleware/__tests__/credential-field-guard.harness.mjs +0 -212
  107. package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts +0 -56
  108. package/esm/middleware/__tests__/mutation-auth-guard.harness.mjs +0 -575
  109. package/esm/middleware/__tests__/rate-limit-test-utils.d.ts +0 -60
  110. package/esm/middleware/__tests__/rate-limit-test-utils.mjs +0 -85
  111. package/esm/middleware/__tests__/ts-node-harness.d.ts +0 -10
  112. package/esm/middleware/__tests__/ts-node-harness.mjs +0 -71
  113. package/health.cjs +0 -274
  114. package/server.cjs +0 -607
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryAPQCache = void 0;
4
+ exports.isAPQEnabled = isAPQEnabled;
5
+ exports.createAPQCache = createAPQCache;
6
+ exports.getCacheControlPlugin = getCacheControlPlugin;
7
+ const disabled_1 = require("@apollo/server/plugin/disabled");
8
+ const logger_1 = require("../utils/logger.cjs");
9
+ /**
10
+ * Default cache TTL for persisted query hashes in seconds.
11
+ * Set to 0 to disable TTL (hashes persist indefinitely in memory).
12
+ */
13
+ const DEFAULT_CACHE_TTL_SECONDS = 0;
14
+ /**
15
+ * Maximum size of the in-memory persisted query cache.
16
+ * Once exceeded, oldest entries are evicted (LRU).
17
+ */
18
+ const DEFAULT_MAX_CACHE_SIZE = 1000;
19
+ /**
20
+ * Simple in-memory key-value cache implementing Apollo's KeyValueCache interface.
21
+ * Provides LRU eviction when the cache reaches maximum capacity.
22
+ */
23
+ class InMemoryAPQCache {
24
+ constructor(maxSize) {
25
+ this.maxSize = maxSize || DEFAULT_MAX_CACHE_SIZE;
26
+ this.cache = new Map();
27
+ }
28
+ async get(key) {
29
+ const entry = this.cache.get(key);
30
+ if (!entry)
31
+ return undefined;
32
+ // Check TTL expiration
33
+ if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {
34
+ this.cache.delete(key);
35
+ return undefined;
36
+ }
37
+ // Move to end for LRU ordering (Map preserves insertion order)
38
+ this.cache.delete(key);
39
+ this.cache.set(key, entry);
40
+ return entry.value;
41
+ }
42
+ async set(key, value, options) {
43
+ var _a;
44
+ // Evict oldest entry if at capacity
45
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
46
+ const oldestKey = this.cache.keys().next().value;
47
+ if (oldestKey !== undefined) {
48
+ this.cache.delete(oldestKey);
49
+ }
50
+ }
51
+ const ttlSeconds = (_a = options === null || options === void 0 ? void 0 : options.ttl) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL_SECONDS;
52
+ const expiresAt = ttlSeconds > 0 ? Date.now() + ttlSeconds * 1000 : null;
53
+ this.cache.set(key, { value, expiresAt });
54
+ }
55
+ async delete(key) {
56
+ return this.cache.delete(key);
57
+ }
58
+ /** Returns the current number of cached entries */
59
+ get size() {
60
+ return this.cache.size;
61
+ }
62
+ /** Clears all cached entries */
63
+ clear() {
64
+ this.cache.clear();
65
+ }
66
+ }
67
+ exports.InMemoryAPQCache = InMemoryAPQCache;
68
+ /**
69
+ * Determines if APQ (Automatic Persisted Queries) is enabled.
70
+ * Enabled by default. Disable via APQ_ENABLED=false.
71
+ */
72
+ function isAPQEnabled() {
73
+ const setting = process.env.APQ_ENABLED;
74
+ if (setting !== undefined) {
75
+ return setting !== 'false' && setting !== '0';
76
+ }
77
+ return true;
78
+ }
79
+ /**
80
+ * Resolves the maximum APQ cache size from environment variables.
81
+ */
82
+ function getMaxCacheSize() {
83
+ const envValue = process.env.APQ_MAX_CACHE_SIZE;
84
+ if (envValue) {
85
+ const parsed = parseInt(envValue, 10);
86
+ if (!isNaN(parsed) && parsed > 0)
87
+ return parsed;
88
+ }
89
+ return DEFAULT_MAX_CACHE_SIZE;
90
+ }
91
+ /**
92
+ * Creates and returns an APQ cache instance for use with Apollo Server.
93
+ *
94
+ * Apollo Server 5 enables APQ by default when a cache is available.
95
+ * To disable APQ entirely, set APQ_ENABLED=false.
96
+ *
97
+ * @returns The configured APQ cache, or undefined if APQ is disabled
98
+ */
99
+ function createAPQCache() {
100
+ if (!isAPQEnabled()) {
101
+ logger_1.logger.info('Automatic Persisted Queries (APQ) disabled');
102
+ return undefined;
103
+ }
104
+ const maxSize = getMaxCacheSize();
105
+ const cache = new InMemoryAPQCache(maxSize);
106
+ logger_1.logger.info('Automatic Persisted Queries (APQ) enabled', {
107
+ maxCacheSize: maxSize,
108
+ });
109
+ return cache;
110
+ }
111
+ /**
112
+ * Returns the Apollo Server cache control plugin configuration.
113
+ * When APQ is disabled, this returns the cache control disabled plugin
114
+ * to explicitly disable caching behavior.
115
+ */
116
+ function getCacheControlPlugin() {
117
+ if (!isAPQEnabled()) {
118
+ return (0, disabled_1.ApolloServerPluginCacheControlDisabled)();
119
+ }
120
+ return undefined;
121
+ }
122
+ //# sourceMappingURL=persisted-queries.js.map
@@ -0,0 +1,40 @@
1
+ import { ApolloServerPluginCacheControlDisabled } from '@apollo/server/plugin/disabled';
2
+ /**
3
+ * Simple in-memory key-value cache implementing Apollo's KeyValueCache interface.
4
+ * Provides LRU eviction when the cache reaches maximum capacity.
5
+ */
6
+ export declare class InMemoryAPQCache {
7
+ private cache;
8
+ private readonly maxSize;
9
+ constructor(maxSize?: number);
10
+ get(key: string): Promise<string | undefined>;
11
+ set(key: string, value: string, options?: {
12
+ ttl?: number | null;
13
+ }): Promise<void>;
14
+ delete(key: string): Promise<boolean>;
15
+ /** Returns the current number of cached entries */
16
+ get size(): number;
17
+ /** Clears all cached entries */
18
+ clear(): void;
19
+ }
20
+ /**
21
+ * Determines if APQ (Automatic Persisted Queries) is enabled.
22
+ * Enabled by default. Disable via APQ_ENABLED=false.
23
+ */
24
+ export declare function isAPQEnabled(): boolean;
25
+ /**
26
+ * Creates and returns an APQ cache instance for use with Apollo Server.
27
+ *
28
+ * Apollo Server 5 enables APQ by default when a cache is available.
29
+ * To disable APQ entirely, set APQ_ENABLED=false.
30
+ *
31
+ * @returns The configured APQ cache, or undefined if APQ is disabled
32
+ */
33
+ export declare function createAPQCache(): InMemoryAPQCache | undefined;
34
+ /**
35
+ * Returns the Apollo Server cache control plugin configuration.
36
+ * When APQ is disabled, this returns the cache control disabled plugin
37
+ * to explicitly disable caching behavior.
38
+ */
39
+ export declare function getCacheControlPlugin(): ReturnType<typeof ApolloServerPluginCacheControlDisabled> | undefined;
40
+ //# sourceMappingURL=persisted-queries.d.ts.map
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WRITE_ONLY_FIELDS = exports.SERVER_ONLY_MODELS = void 0;
4
+ exports.isServerOnlyModel = isServerOnlyModel;
5
+ exports.withoutServerOnlyResolvers = withoutServerOnlyResolvers;
6
+ exports.isServerOnlyTypeName = isServerOnlyTypeName;
7
+ exports.writeOnlyOutputFieldsFor = writeOnlyOutputFieldsFor;
8
+ exports.withoutServerOnlySchemaSurface = withoutServerOnlySchemaSurface;
9
+ const graphql_1 = require("graphql");
10
+ const generated_type_names_1 = require("../middleware/generated-type-names.cjs");
11
+ /**
12
+ * Prisma models that are server-only: they live in the schema (so Prisma owns
13
+ * their migrations and the client can read them) but are NEVER part of the
14
+ * GraphQL API or the published `adaptic.*` client surface.
15
+ *
16
+ * typegraphql-prisma has no model-level opt-out, so the exclusion is applied at
17
+ * every point where the generated surface is assembled:
18
+ * - `src/server.ts` drops the model's generated resolver classes before
19
+ * `buildSchema`, so no query, mutation or object type for it exists, and
20
+ * strips what the omit directive cannot reach from the built schema (the
21
+ * relation count on the parent's `_count` type and the filter inputs it
22
+ * drags in);
23
+ * - `src/modules/index.ts`, `generateSelections.ts` and `generateStrings.ts`
24
+ * skip it, so no CRUD functions, selection set or typeString is published;
25
+ * - any relation field that points at it from an exposed model carries
26
+ * `@TypeGraphQL.omit(output: true, input: true)` plus `GQL.SKIP=true` and
27
+ * `TYPESTRING.SKIP=true` in the schema.
28
+ *
29
+ * TradeRestatement: the trade restatement ledger. Written only by operator
30
+ * restatement scripts inside the repair transaction; with the resolver
31
+ * authChecker and the mutation guard both still shadow-first, a generated CRUD
32
+ * surface would let any caller rewrite or delete the record of what was
33
+ * restated, and expose whole prior trade rows.
34
+ */
35
+ exports.SERVER_ONLY_MODELS = ['TradeRestatement'];
36
+ const SERVER_ONLY_MODEL_SET = new Set(exports.SERVER_ONLY_MODELS);
37
+ /**
38
+ * @param modelName - A Prisma model name (PascalCase).
39
+ * @returns Whether the model must be kept off the GraphQL/client surface.
40
+ */
41
+ function isServerOnlyModel(modelName) {
42
+ return SERVER_ONLY_MODEL_SET.has(modelName);
43
+ }
44
+ /** Suffixes typegraphql-prisma gives the per-model classes in its `resolvers` export. */
45
+ const GENERATED_RESOLVER_SUFFIXES = ['CrudResolver', 'RelationsResolver'];
46
+ /**
47
+ * Removes the generated resolver classes of server-only models.
48
+ *
49
+ * @param resolvers - The generated `resolvers` array from typegraphql-prisma.
50
+ * @returns The array without any `<Model>CrudResolver` / `<Model>RelationsResolver`
51
+ * whose model is server-only, non-empty as `buildSchema` requires.
52
+ */
53
+ function withoutServerOnlyResolvers(resolvers) {
54
+ const kept = resolvers.filter((resolver) => {
55
+ for (const suffix of GENERATED_RESOLVER_SUFFIXES) {
56
+ if (resolver.name.endsWith(suffix)) {
57
+ return !isServerOnlyModel(resolver.name.slice(0, -suffix.length));
58
+ }
59
+ }
60
+ return true;
61
+ });
62
+ const [first, ...rest] = kept;
63
+ if (first === undefined) {
64
+ throw new Error('withoutServerOnlyResolvers: no resolvers left');
65
+ }
66
+ return [first, ...rest];
67
+ }
68
+ /**
69
+ * @param typeName - A GraphQL type name.
70
+ * @returns Whether the type is a server-only model or one of its generated
71
+ * companions (`<Model>WhereInput`, `<Model>ListRelationFilter`, ...).
72
+ */
73
+ function isServerOnlyTypeName(typeName) {
74
+ return exports.SERVER_ONLY_MODELS.some((model) => typeName === model ||
75
+ (typeName.startsWith(model) &&
76
+ /^[A-Z]/.test(typeName.slice(model.length))));
77
+ }
78
+ /**
79
+ * Write-only columns, by Prisma model: a caller may set them through the
80
+ * generated create / update inputs, but no output type returns them. They are
81
+ * read only server-side, through Prisma.
82
+ *
83
+ * Each column also carries `@TypeGraphQL.omit(output: true, input: ["where",
84
+ * "orderBy"])`, `GQL.SKIP=true` and `TYPESTRING.SKIP=true` in the schema. The
85
+ * omit directive removes the column from the model type and the predicate
86
+ * inputs only: typegraphql-prisma still emits it on the model's `GroupBy`,
87
+ * `MinAggregate`, `MaxAggregate` and `CountAggregate` types and on the
88
+ * `CreateManyAndReturn` / `UpdateManyAndReturn` row types, where it would be
89
+ * served by value. {@link withoutServerOnlySchemaSurface} removes it there.
90
+ *
91
+ * UserTotp: the TOTP shared secret (encrypted at rest) and the hashes of the
92
+ * unused recovery codes. Either lets its holder pass the second factor.
93
+ */
94
+ exports.WRITE_ONLY_FIELDS = new Map([['UserTotp', new Set(['secretEnc', 'recoveryCodesHash'])]]);
95
+ const WRITE_ONLY_OUTPUTS = (0, generated_type_names_1.indexGeneratedTypes)(exports.WRITE_ONLY_FIELDS);
96
+ /** Suffix of the generated per-model count aggregate output type. */
97
+ const COUNT_AGGREGATE_SUFFIX = 'CountAggregate';
98
+ /**
99
+ * @param typeName - A GraphQL output type name.
100
+ * @returns The write-only columns that type would serve, or `undefined`.
101
+ */
102
+ function writeOnlyOutputFieldsFor(typeName) {
103
+ const valued = WRITE_ONLY_OUTPUTS.outputFields(typeName);
104
+ if (valued)
105
+ return valued;
106
+ // The count aggregate returns how many rows hold a value, not the value;
107
+ // it is removed too so no output type names a write-only column at all.
108
+ return typeName.endsWith(COUNT_AGGREGATE_SUFFIX)
109
+ ? exports.WRITE_ONLY_FIELDS.get(typeName.slice(0, -COUNT_AGGREGATE_SUFFIX.length))
110
+ : undefined;
111
+ }
112
+ /**
113
+ * Removes every field that returns, or takes an argument of, a server-only
114
+ * type, and every write-only column ({@link WRITE_ONLY_FIELDS}) from the
115
+ * output types that would serve it, then rebuilds the schema so types
116
+ * reachable only through those fields drop out of the type map (and out of
117
+ * introspection).
118
+ *
119
+ * typegraphql-prisma's `@TypeGraphQL.omit` hides a relation field from the
120
+ * model type and its inputs but still emits the relation's count on the
121
+ * parent's `<Model>Count` type (e.g. `TradeCount.restatements(where:
122
+ * TradeRestatementWhereInput)`), which would let a caller count and filter
123
+ * ledger rows. Resolver functions are untouched: the rebuilt schema reuses the
124
+ * same type objects, so middleware and auth decorators applied by `buildSchema`
125
+ * carry over.
126
+ *
127
+ * @param schema - The schema returned by `buildSchema`.
128
+ * @returns A schema with no server-only type or field.
129
+ */
130
+ function withoutServerOnlySchemaSurface(schema) {
131
+ for (const type of Object.values(schema.getTypeMap())) {
132
+ if (type.name.startsWith('__') || isServerOnlyTypeName(type.name)) {
133
+ continue;
134
+ }
135
+ if ((0, graphql_1.isObjectType)(type) || (0, graphql_1.isInterfaceType)(type)) {
136
+ const fields = type.getFields();
137
+ const writeOnly = writeOnlyOutputFieldsFor(type.name);
138
+ for (const [name, field] of Object.entries(fields)) {
139
+ if (writeOnly === null || writeOnly === void 0 ? void 0 : writeOnly.has(name)) {
140
+ delete fields[name];
141
+ continue;
142
+ }
143
+ const touchesServerOnly = isServerOnlyTypeName((0, graphql_1.getNamedType)(field.type).name) ||
144
+ field.args.some((arg) => isServerOnlyTypeName((0, graphql_1.getNamedType)(arg.type).name));
145
+ if (touchesServerOnly) {
146
+ delete fields[name];
147
+ }
148
+ }
149
+ }
150
+ else if ((0, graphql_1.isInputObjectType)(type)) {
151
+ const fields = type.getFields();
152
+ for (const [name, field] of Object.entries(fields)) {
153
+ if (isServerOnlyTypeName((0, graphql_1.getNamedType)(field.type).name)) {
154
+ delete fields[name];
155
+ }
156
+ }
157
+ }
158
+ }
159
+ // Rebuild from the root types only, so companions that were reachable solely
160
+ // through the stripped fields (filters for the ledger's own columns) leave the
161
+ // type map too. `buildSchema` is not given `orphanedTypes`, so every type it
162
+ // emits is reachable from a root; nothing legitimate is lost.
163
+ const config = schema.toConfig();
164
+ return new graphql_1.GraphQLSchema({ ...config, types: [] });
165
+ }
166
+ //# sourceMappingURL=server-only-models.js.map
@@ -0,0 +1,89 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ /**
3
+ * Prisma models that are server-only: they live in the schema (so Prisma owns
4
+ * their migrations and the client can read them) but are NEVER part of the
5
+ * GraphQL API or the published `adaptic.*` client surface.
6
+ *
7
+ * typegraphql-prisma has no model-level opt-out, so the exclusion is applied at
8
+ * every point where the generated surface is assembled:
9
+ * - `src/server.ts` drops the model's generated resolver classes before
10
+ * `buildSchema`, so no query, mutation or object type for it exists, and
11
+ * strips what the omit directive cannot reach from the built schema (the
12
+ * relation count on the parent's `_count` type and the filter inputs it
13
+ * drags in);
14
+ * - `src/modules/index.ts`, `generateSelections.ts` and `generateStrings.ts`
15
+ * skip it, so no CRUD functions, selection set or typeString is published;
16
+ * - any relation field that points at it from an exposed model carries
17
+ * `@TypeGraphQL.omit(output: true, input: true)` plus `GQL.SKIP=true` and
18
+ * `TYPESTRING.SKIP=true` in the schema.
19
+ *
20
+ * TradeRestatement: the trade restatement ledger. Written only by operator
21
+ * restatement scripts inside the repair transaction; with the resolver
22
+ * authChecker and the mutation guard both still shadow-first, a generated CRUD
23
+ * surface would let any caller rewrite or delete the record of what was
24
+ * restated, and expose whole prior trade rows.
25
+ */
26
+ export declare const SERVER_ONLY_MODELS: readonly string[];
27
+ /**
28
+ * @param modelName - A Prisma model name (PascalCase).
29
+ * @returns Whether the model must be kept off the GraphQL/client surface.
30
+ */
31
+ export declare function isServerOnlyModel(modelName: string): boolean;
32
+ /**
33
+ * Removes the generated resolver classes of server-only models.
34
+ *
35
+ * @param resolvers - The generated `resolvers` array from typegraphql-prisma.
36
+ * @returns The array without any `<Model>CrudResolver` / `<Model>RelationsResolver`
37
+ * whose model is server-only, non-empty as `buildSchema` requires.
38
+ */
39
+ export declare function withoutServerOnlyResolvers<T extends {
40
+ name: string;
41
+ }>(resolvers: readonly T[]): [T, ...T[]];
42
+ /**
43
+ * @param typeName - A GraphQL type name.
44
+ * @returns Whether the type is a server-only model or one of its generated
45
+ * companions (`<Model>WhereInput`, `<Model>ListRelationFilter`, ...).
46
+ */
47
+ export declare function isServerOnlyTypeName(typeName: string): boolean;
48
+ /**
49
+ * Write-only columns, by Prisma model: a caller may set them through the
50
+ * generated create / update inputs, but no output type returns them. They are
51
+ * read only server-side, through Prisma.
52
+ *
53
+ * Each column also carries `@TypeGraphQL.omit(output: true, input: ["where",
54
+ * "orderBy"])`, `GQL.SKIP=true` and `TYPESTRING.SKIP=true` in the schema. The
55
+ * omit directive removes the column from the model type and the predicate
56
+ * inputs only: typegraphql-prisma still emits it on the model's `GroupBy`,
57
+ * `MinAggregate`, `MaxAggregate` and `CountAggregate` types and on the
58
+ * `CreateManyAndReturn` / `UpdateManyAndReturn` row types, where it would be
59
+ * served by value. {@link withoutServerOnlySchemaSurface} removes it there.
60
+ *
61
+ * UserTotp: the TOTP shared secret (encrypted at rest) and the hashes of the
62
+ * unused recovery codes. Either lets its holder pass the second factor.
63
+ */
64
+ export declare const WRITE_ONLY_FIELDS: ReadonlyMap<string, ReadonlySet<string>>;
65
+ /**
66
+ * @param typeName - A GraphQL output type name.
67
+ * @returns The write-only columns that type would serve, or `undefined`.
68
+ */
69
+ export declare function writeOnlyOutputFieldsFor(typeName: string): ReadonlySet<string> | undefined;
70
+ /**
71
+ * Removes every field that returns, or takes an argument of, a server-only
72
+ * type, and every write-only column ({@link WRITE_ONLY_FIELDS}) from the
73
+ * output types that would serve it, then rebuilds the schema so types
74
+ * reachable only through those fields drop out of the type map (and out of
75
+ * introspection).
76
+ *
77
+ * typegraphql-prisma's `@TypeGraphQL.omit` hides a relation field from the
78
+ * model type and its inputs but still emits the relation's count on the
79
+ * parent's `<Model>Count` type (e.g. `TradeCount.restatements(where:
80
+ * TradeRestatementWhereInput)`), which would let a caller count and filter
81
+ * ledger rows. Resolver functions are untouched: the rebuilt schema reuses the
82
+ * same type objects, so middleware and auth decorators applied by `buildSchema`
83
+ * carry over.
84
+ *
85
+ * @param schema - The schema returned by `buildSchema`.
86
+ * @returns A schema with no server-only type or field.
87
+ */
88
+ export declare function withoutServerOnlySchemaSurface(schema: GraphQLSchema): GraphQLSchema;
89
+ //# sourceMappingURL=server-only-models.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Initializes OpenTelemetry tracing for the backend-legacy service.
3
+ *
4
+ * Configures:
5
+ * - HTTP instrumentation for incoming/outgoing HTTP requests
6
+ * - Express instrumentation for route-level spans
7
+ * - GraphQL instrumentation for resolver-level spans
8
+ * - OTLP HTTP exporter for sending traces to a collector (e.g., Jaeger, Grafana Tempo)
9
+ *
10
+ * Environment variables:
11
+ * - OTEL_TRACING_ENABLED: Explicit on/off ('true'/'false'). Defaults to on in production/staging.
12
+ * - OTEL_EXPORTER_OTLP_ENDPOINT: Collector endpoint (default: http://localhost:4318/v1/traces)
13
+ * - OTEL_SERVICE_NAME: Override service name (default: 'backend-legacy')
14
+ *
15
+ * Call this function before any other imports that need instrumentation (e.g., before Express/Apollo setup).
16
+ */
17
+ export declare function initTracing(): void;
18
+ /**
19
+ * Gracefully shuts down the OpenTelemetry SDK.
20
+ * Should be called during application shutdown (SIGTERM/SIGINT handlers).
21
+ * Flushes any pending spans before shutting down.
22
+ */
23
+ export declare function shutdownTracing(): Promise<void>;
24
+ //# sourceMappingURL=tracing.d.ts.map
@@ -75,6 +75,18 @@ export declare const MAX_SERVICE_TOKEN_CLOCK_SKEW_SEC = 60;
75
75
  * rotation.
76
76
  */
77
77
  export type ServiceKeySlot = 'primary' | 'previous';
78
+ /**
79
+ * Boot-time guard: refuse to start when a provisioned service secret (either
80
+ * slot) equals `JWT_SECRET`.
81
+ *
82
+ * `verifyServiceToken` already refuses per request, but that surfaces only as
83
+ * a stream of 401s on service calls after a deploy. Failing at boot puts the
84
+ * misconfiguration on the deploy, where it is caught before traffic. An
85
+ * unprovisioned service path is not an error — it is simply disabled.
86
+ *
87
+ * @throws {Error} When a service secret collides with the user-session secret.
88
+ */
89
+ export declare function assertServiceSecretsDistinctFromJwtSecret(): void;
78
90
  /**
79
91
  * Attempt to establish a service principal from a bearer token.
80
92
  *
@@ -132,6 +132,31 @@ function resolveServiceSecrets() {
132
132
  }
133
133
  return slots;
134
134
  }
135
+ const SECRET_COLLISION_MESSAGE = '[auth] BACKEND_SERVICE_JWT_SECRET (or its _PREVIOUS slot) is identical to JWT_SECRET. ' +
136
+ 'These MUST be distinct secrets — sharing them collapses the ' +
137
+ 'separation between end-user and service identity. Refusing to ' +
138
+ 'verify service tokens until they differ.';
139
+ function collidesWithUserSecret(slots) {
140
+ return slots.some(({ secret }) => secret === jwtSecret);
141
+ }
142
+ /**
143
+ * Boot-time guard: refuse to start when a provisioned service secret (either
144
+ * slot) equals `JWT_SECRET`.
145
+ *
146
+ * `verifyServiceToken` already refuses per request, but that surfaces only as
147
+ * a stream of 401s on service calls after a deploy. Failing at boot puts the
148
+ * misconfiguration on the deploy, where it is caught before traffic. An
149
+ * unprovisioned service path is not an error — it is simply disabled.
150
+ *
151
+ * @throws {Error} When a service secret collides with the user-session secret.
152
+ */
153
+ export function assertServiceSecretsDistinctFromJwtSecret() {
154
+ const slots = resolveServiceSecrets();
155
+ if (slots !== null && collidesWithUserSecret(slots)) {
156
+ logger.error(SECRET_COLLISION_MESSAGE);
157
+ throw new Error('BACKEND_SERVICE_JWT_SECRET (or _PREVIOUS) must differ from JWT_SECRET.');
158
+ }
159
+ }
135
160
  /**
136
161
  * Verify a token's signature and bound claims against one secret.
137
162
  *
@@ -208,11 +233,8 @@ export function verifyServiceToken(token, nowMs = Date.now()) {
208
233
  // which bypasses every tenancy scope and role gate. Refuse rather than
209
234
  // silently operate with the separation collapsed. This holds for the
210
235
  // previous slot too: a rotation must not reopen the hole.
211
- if (slots.some(({ secret }) => secret === jwtSecret)) {
212
- logger.error('[auth] BACKEND_SERVICE_JWT_SECRET (or its _PREVIOUS slot) is identical to JWT_SECRET. ' +
213
- 'These MUST be distinct secrets — sharing them collapses the ' +
214
- 'separation between end-user and service identity. Refusing to ' +
215
- 'verify service tokens until they differ.');
236
+ if (collidesWithUserSecret(slots)) {
237
+ logger.error(SECRET_COLLISION_MESSAGE);
216
238
  throw new AuthError('invalid_token', 'misconfigured');
217
239
  }
218
240
  let payload = null;
@@ -14,7 +14,11 @@ const DEV_FALLBACK_SECRET = 'development_secret_key_for_local_testing_only_do_no
14
14
  const isProduction = process.env.NODE_ENV === 'production';
15
15
  function resolveJwtSecret() {
16
16
  // Try JWT_SECRET first, then fall back to NEXTAUTH_SECRET for compatibility
17
- const secret = process.env.JWT_SECRET || process.env.NEXTAUTH_SECRET;
17
+ // Trimmed so a stray newline or space from a pasted dashboard value cannot
18
+ // make this differ from the same secret as `service-token.ts` reads it (that
19
+ // module trims), which would defeat its JWT_SECRET collision check. A
20
+ // whitespace-only JWT_SECRET counts as unset and falls through.
21
+ const secret = process.env.JWT_SECRET?.trim() || process.env.NEXTAUTH_SECRET?.trim();
18
22
  if (!secret) {
19
23
  if (isProduction) {
20
24
  logger.error('[SECURITY] FATAL: JWT_SECRET environment variable is not set. ' +
@@ -44,9 +44,9 @@ const crudResolvers = __importStar(require("./resolvers/crud/resolvers-crud.inde
44
44
  const argsTypes = __importStar(require("./resolvers/crud/args.index.cjs"));
45
45
  const actionResolvers = __importStar(require("./resolvers/crud/resolvers-actions.index.cjs"));
46
46
  const relationResolvers = __importStar(require("./resolvers/relations/resolvers.index.cjs"));
47
- const models = __importStar(require("./models.cjs"));
48
- const outputTypes = __importStar(require("./resolvers/outputs.cjs"));
49
- const inputTypes = __importStar(require("./resolvers/inputs.cjs"));
47
+ const models = __importStar(require("./models/index.cjs"));
48
+ const outputTypes = __importStar(require("./resolvers/outputs/index.cjs"));
49
+ const inputTypes = __importStar(require("./resolvers/inputs/index.cjs"));
50
50
  const crudResolversMap = {
51
51
  Configuration: crudResolvers.ConfigurationCrudResolver,
52
52
  MarketSentiment: crudResolvers.MarketSentimentCrudResolver,
@@ -39,14 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.resolvers = exports.relationResolvers = exports.crudResolvers = void 0;
40
40
  const crudResolversImport = __importStar(require("./resolvers/crud/resolvers-crud.index.cjs"));
41
41
  const relationResolversImport = __importStar(require("./resolvers/relations/resolvers.index.cjs"));
42
- __exportStar(require("./enums.cjs"), exports);
43
- __exportStar(require("./models.cjs"), exports);
44
- __exportStar(require("./resolvers/crud.cjs"), exports);
42
+ __exportStar(require("./enums/index.cjs"), exports);
43
+ __exportStar(require("./models/index.cjs"), exports);
44
+ __exportStar(require("./resolvers/crud/index.cjs"), exports);
45
45
  exports.crudResolvers = Object.values(crudResolversImport);
46
- __exportStar(require("./resolvers/relations.cjs"), exports);
46
+ __exportStar(require("./resolvers/relations/index.cjs"), exports);
47
47
  exports.relationResolvers = Object.values(relationResolversImport);
48
- __exportStar(require("./resolvers/inputs.cjs"), exports);
49
- __exportStar(require("./resolvers/outputs.cjs"), exports);
48
+ __exportStar(require("./resolvers/inputs/index.cjs"), exports);
49
+ __exportStar(require("./resolvers/outputs/index.cjs"), exports);
50
50
  __exportStar(require("./enhance.cjs"), exports);
51
51
  __exportStar(require("./scalars.cjs"), exports);
52
52
  exports.resolvers = [