@cullet/erp-core 1.0.2 → 1.0.4
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.
- package/README.md +24 -24
- package/dist/gate-engine-registry.js.map +1 -1
- package/dist/gate-v1-payload.schema.js +5 -0
- package/dist/gate-v1-payload.schema.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/outcome.js.map +1 -1
- package/dist/policies/engines/v1/gate/index.d.ts +1 -0
- package/dist/policies/engines/v1/gate/index.js.map +1 -1
- package/dist/policy-service.js.map +1 -1
- package/dist/validation-code.js.map +1 -1
- package/dist/validation-error.js.map +1 -1
- package/dist/validation-field.js.map +1 -1
- package/meta.json +67 -67
- package/package.json +56 -56
- package/src/core/application/commands/command.ts +3 -3
- package/src/core/application/commands/requested-by.ts +60 -60
- package/src/core/application/index.ts +21 -21
- package/src/core/application/policy-error-mapper.ts +54 -54
- package/src/core/application/ports/index.ts +6 -6
- package/src/core/application/ports/logger.port.ts +4 -4
- package/src/core/application/ports/metrics.port.ts +3 -3
- package/src/core/application/ports/policy-port.ts +7 -7
- package/src/core/application/ports/repository.port.ts +3 -3
- package/src/core/application/ports/temporal-repository.port.ts +4 -4
- package/src/core/application/ports/tracer.port.ts +7 -7
- package/src/core/application/queries/query.ts +13 -13
- package/src/core/application/temporal/index.ts +7 -7
- package/src/core/application/temporal/temporal-context.ts +20 -20
- package/src/core/application/temporal/temporal-use-case.ts +22 -22
- package/src/core/application/use-case.ts +10 -10
- package/src/core/config/core-config.instance.ts +1 -1
- package/src/core/config/core-config.ts +59 -59
- package/src/core/config/index.ts +6 -6
- package/src/core/config/policy-reporter.ts +31 -31
- package/src/core/config/silent-policy-reporter.ts +1 -1
- package/src/core/domain/entity.ts +44 -44
- package/src/core/domain/rulesets/entity-ruleset.contracts.ts +6 -6
- package/src/core/domain/rulesets/ruleset-registry.ts +49 -49
- package/src/core/domain/rulesets/ruleset.contracts.ts +6 -6
- package/src/core/domain/rulesets/value-object-ruleset.contracts.ts +5 -5
- package/src/core/domain/temporal/index.ts +11 -11
- package/src/core/domain/temporal/temporal-range.ts +16 -16
- package/src/core/domain/temporal/temporal-snapshot.ts +24 -24
- package/src/core/domain/temporal/transaction-time.ts +30 -30
- package/src/core/domain/temporal/valid-time.ts +29 -29
- package/src/core/domain/value-object.ts +16 -16
- package/src/core/errors/app-error.ts +64 -64
- package/src/core/errors/authentication-error.ts +134 -134
- package/src/core/errors/authorization-error.ts +154 -154
- package/src/core/errors/business-rule-violation-error.ts +15 -15
- package/src/core/errors/conflict-error.ts +202 -201
- package/src/core/errors/error-codes.ts +48 -48
- package/src/core/errors/idempotency-error.ts +324 -320
- package/src/core/errors/index.ts +50 -50
- package/src/core/errors/integration-error.ts +120 -120
- package/src/core/errors/legacy-incompatible-error.ts +13 -13
- package/src/core/errors/not-found-error.ts +14 -14
- package/src/core/errors/serialization-error.ts +167 -167
- package/src/core/errors/temporal-error.ts +109 -107
- package/src/core/errors/types.ts +35 -35
- package/src/core/errors/unexpected-error.ts +10 -10
- package/src/core/errors/utils/index.ts +2 -2
- package/src/core/errors/utils/json-safe.ts +53 -53
- package/src/core/errors/validation-error.ts +18 -18
- package/src/core/exceptions/business-rule-violation-exception.ts +6 -6
- package/src/core/exceptions/domain-exception.ts +5 -5
- package/src/core/exceptions/entity-not-found-exception.ts +6 -6
- package/src/core/exceptions/invalid-state-transition-exception.ts +8 -8
- package/src/core/exceptions/invariant-violation-exception.ts +3 -3
- package/src/core/exceptions/validation-code.ts +35 -29
- package/src/core/exceptions/validation-exception.ts +19 -19
- package/src/core/exceptions/validation-field.ts +20 -19
- package/src/core/index.ts +7 -7
- package/src/core/policies/asof/asof.ts +47 -47
- package/src/core/policies/catalog/catalog.instance.ts +8 -6
- package/src/core/policies/catalog/index.ts +4 -4
- package/src/core/policies/catalog/policy-catalog-entry.ts +199 -197
- package/src/core/policies/catalog/policy-catalog.ts +101 -101
- package/src/core/policies/catalog/policy-key.ts +51 -51
- package/src/core/policies/context/context-builder.ts +335 -313
- package/src/core/policies/context/context-registry.instance.ts +9 -9
- package/src/core/policies/context/context-registry.ts +61 -61
- package/src/core/policies/context/context-resolver.ts +12 -12
- package/src/core/policies/context/context-seed.ts +19 -15
- package/src/core/policies/context/index.ts +9 -9
- package/src/core/policies/context/path.ts +135 -128
- package/src/core/policies/defs/in-memory-policy-definition-repo.ts +56 -55
- package/src/core/policies/defs/index.ts +10 -10
- package/src/core/policies/defs/policy-definition-repository.ts +3 -3
- package/src/core/policies/defs/policy-definition.ts +143 -142
- package/src/core/policies/defs/policy-scope.ts +21 -19
- package/src/core/policies/defs/policy-semver.ts +51 -51
- package/src/core/policies/engines/compute-engine-registry.ts +43 -43
- package/src/core/policies/engines/compute-evaluator-registry.ts +20 -20
- package/src/core/policies/engines/compute-registry.ts +45 -45
- package/src/core/policies/engines/compute-types.ts +15 -15
- package/src/core/policies/engines/condition-evaluator-reporter.ts +17 -17
- package/src/core/policies/engines/gate-engine-registry.ts +27 -25
- package/src/core/policies/engines/gate-types.ts +28 -28
- package/src/core/policies/engines/index.ts +28 -28
- package/src/core/policies/engines/parse-compute-payload.ts +51 -45
- package/src/core/policies/engines/parse-gate-payload.ts +42 -42
- package/src/core/policies/engines/v1/compute/compute-engine-v1.ts +39 -37
- package/src/core/policies/engines/v1/compute/compute-payload.schema.ts +43 -41
- package/src/core/policies/engines/v1/compute/index.ts +6 -6
- package/src/core/policies/engines/v1/compute/resolve-decision-table-v1.ts +41 -39
- package/src/core/policies/engines/v1/condition-evaluator.ts +557 -504
- package/src/core/policies/engines/v1/condition-schema.ts +35 -35
- package/src/core/policies/engines/v1/condition-types.ts +21 -21
- package/src/core/policies/engines/v1/gate/gate-engine-v1.ts +134 -130
- package/src/core/policies/engines/v1/gate/gate-types-v1.ts +5 -5
- package/src/core/policies/engines/v1/gate/gate-v1-payload.schema.ts +32 -30
- package/src/core/policies/engines/v1/gate/index.ts +4 -4
- package/src/core/policies/engines/v1/index.ts +8 -8
- package/src/core/policies/index.ts +72 -72
- package/src/core/policies/package/policy-package.ts +3 -3
- package/src/core/policies/policy-ids.ts +25 -25
- package/src/core/policies/resolver/policy-resolver.ts +34 -34
- package/src/core/policies/service/index.ts +6 -6
- package/src/core/policies/service/policy-evaluation-error.ts +141 -133
- package/src/core/policies/service/policy-service.ts +432 -419
- package/src/core/policies/utils/date.ts +3 -3
- package/src/core/policies/utils/hash.ts +61 -61
- package/src/core/result/outcome.ts +131 -126
- package/src/core/result/result.ts +130 -127
- package/src/core/shared/aggregate-version.ts +5 -5
- package/src/core/shared/hashing.ts +18 -18
- package/src/core/shared/immutable.ts +29 -29
- package/src/core/shared/temporal-guards.ts +9 -9
- package/src/core/versioning/domain-event-contracts.ts +40 -40
- package/src/core/versioning/version.ts +19 -19
- package/src/examples/rulesets/entity/order-creation-rules-v1.ts +18 -18
- package/src/examples/rulesets/entity/order-invariants-v1.ts +31 -29
- package/src/examples/rulesets/entity/order-invariants-v2.ts +12 -12
- package/src/examples/rulesets/entity/order.ts +127 -127
- package/src/examples/rulesets/value-object/cpf-rules-v1.ts +41 -39
- package/src/examples/rulesets/value-object/cpf-rules-v2.ts +14 -12
- package/src/examples/rulesets/value-object/cpf.ts +24 -24
- package/src/examples/rulesets/value-object/customer.ts +42 -39
- package/src/examples/rulesets/value-object/person-name-rules-v1.ts +27 -27
- package/src/examples/rulesets/value-object/person-name-rules-v2.ts +13 -13
- package/src/examples/rulesets/value-object/person-name.ts +29 -26
- package/src/index.ts +2 -2
- package/src/version.ts +1 -1
|
@@ -4,90 +4,17 @@ import { AppError } from "./app-error";
|
|
|
4
4
|
import { ErrorCodes } from "./error-codes";
|
|
5
5
|
|
|
6
6
|
export type IdempotencyFailureKind =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
| "key_missing"
|
|
8
|
+
| "in_progress"
|
|
9
|
+
| "payload_mismatch"
|
|
10
|
+
| "replay_not_supported"
|
|
11
|
+
| "unknown";
|
|
12
12
|
|
|
13
13
|
export type IdempotencyErrorMetadata = {
|
|
14
|
-
|
|
15
|
-
operation: string;
|
|
16
|
-
scope?: string;
|
|
17
|
-
entity?: string;
|
|
18
|
-
keyHash?: string;
|
|
19
|
-
keyPreview?: string;
|
|
20
|
-
incomingPayloadHash?: string;
|
|
21
|
-
existingPayloadHash?: string;
|
|
22
|
-
idempotencyRecordId?: string;
|
|
23
|
-
correlationId?: string;
|
|
24
|
-
requestId?: string;
|
|
25
|
-
commandId?: string;
|
|
26
|
-
detectedAtIso?: string;
|
|
27
|
-
hint?: string;
|
|
28
|
-
details?: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type IdempotencyErrorConstructorInput = {
|
|
32
|
-
message: string;
|
|
33
|
-
code: string;
|
|
34
|
-
kind: IdempotencyFailureKind;
|
|
35
|
-
metadata: Omit<IdempotencyErrorMetadata, "kind">;
|
|
36
|
-
cause?: unknown;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
abstract class IdempotencyError extends AppError {
|
|
40
|
-
public readonly kind: IdempotencyFailureKind;
|
|
41
|
-
|
|
42
|
-
protected constructor(input: IdempotencyErrorConstructorInput) {
|
|
43
|
-
super(input.message, input.code, {
|
|
44
|
-
cause: input.cause,
|
|
45
|
-
metadata: { kind: input.kind, ...input.metadata },
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
this.kind = input.kind;
|
|
49
|
-
Object.freeze(this);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static keyMissing(input: {
|
|
53
|
-
operation: string;
|
|
54
|
-
scope?: string;
|
|
55
|
-
entity?: string;
|
|
56
|
-
correlationId?: string;
|
|
57
|
-
requestId?: string;
|
|
58
|
-
commandId?: string;
|
|
59
|
-
detectedAtIso?: string;
|
|
60
|
-
hint?: string;
|
|
61
|
-
details?: string;
|
|
62
|
-
cause?: unknown;
|
|
63
|
-
}): IdempotencyKeyMissingError {
|
|
64
|
-
return IdempotencyKeyMissingError.detected(input);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static inProgress(input: {
|
|
14
|
+
kind: IdempotencyFailureKind;
|
|
68
15
|
operation: string;
|
|
69
16
|
scope?: string;
|
|
70
17
|
entity?: string;
|
|
71
|
-
key?: string;
|
|
72
|
-
keyHash?: string;
|
|
73
|
-
keyPreview?: string;
|
|
74
|
-
idempotencyRecordId?: string;
|
|
75
|
-
correlationId?: string;
|
|
76
|
-
requestId?: string;
|
|
77
|
-
commandId?: string;
|
|
78
|
-
detectedAtIso?: string;
|
|
79
|
-
hint?: string;
|
|
80
|
-
details?: string;
|
|
81
|
-
cause?: unknown;
|
|
82
|
-
}): IdempotencyInProgressError {
|
|
83
|
-
return IdempotencyInProgressError.detected(input);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static payloadMismatch(input: {
|
|
87
|
-
operation: string;
|
|
88
|
-
scope?: string;
|
|
89
|
-
entity?: string;
|
|
90
|
-
key?: string;
|
|
91
18
|
keyHash?: string;
|
|
92
19
|
keyPreview?: string;
|
|
93
20
|
incomingPayloadHash?: string;
|
|
@@ -99,274 +26,351 @@ abstract class IdempotencyError extends AppError {
|
|
|
99
26
|
detectedAtIso?: string;
|
|
100
27
|
hint?: string;
|
|
101
28
|
details?: string;
|
|
102
|
-
|
|
103
|
-
}): IdempotencyPayloadMismatchError {
|
|
104
|
-
return IdempotencyPayloadMismatchError.detected(input);
|
|
105
|
-
}
|
|
29
|
+
};
|
|
106
30
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
keyHash?: string;
|
|
113
|
-
keyPreview?: string;
|
|
114
|
-
idempotencyRecordId?: string;
|
|
115
|
-
correlationId?: string;
|
|
116
|
-
requestId?: string;
|
|
117
|
-
commandId?: string;
|
|
118
|
-
detectedAtIso?: string;
|
|
119
|
-
hint?: string;
|
|
120
|
-
details?: string;
|
|
31
|
+
type IdempotencyErrorConstructorInput = {
|
|
32
|
+
message: string;
|
|
33
|
+
code: string;
|
|
34
|
+
kind: IdempotencyFailureKind;
|
|
35
|
+
metadata: Omit<IdempotencyErrorMetadata, "kind">;
|
|
121
36
|
cause?: unknown;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
abstract class IdempotencyError extends AppError {
|
|
40
|
+
public readonly kind: IdempotencyFailureKind;
|
|
41
|
+
|
|
42
|
+
protected constructor(input: IdempotencyErrorConstructorInput) {
|
|
43
|
+
super(input.message, input.code, {
|
|
44
|
+
cause: input.cause,
|
|
45
|
+
metadata: { kind: input.kind, ...input.metadata },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
this.kind = input.kind;
|
|
49
|
+
Object.freeze(this);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static keyMissing(input: {
|
|
53
|
+
operation: string;
|
|
54
|
+
scope?: string;
|
|
55
|
+
entity?: string;
|
|
56
|
+
correlationId?: string;
|
|
57
|
+
requestId?: string;
|
|
58
|
+
commandId?: string;
|
|
59
|
+
detectedAtIso?: string;
|
|
60
|
+
hint?: string;
|
|
61
|
+
details?: string;
|
|
62
|
+
cause?: unknown;
|
|
63
|
+
}): IdempotencyKeyMissingError {
|
|
64
|
+
return IdempotencyKeyMissingError.detected(input);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static inProgress(input: {
|
|
68
|
+
operation: string;
|
|
69
|
+
scope?: string;
|
|
70
|
+
entity?: string;
|
|
71
|
+
key?: string;
|
|
72
|
+
keyHash?: string;
|
|
73
|
+
keyPreview?: string;
|
|
74
|
+
idempotencyRecordId?: string;
|
|
75
|
+
correlationId?: string;
|
|
76
|
+
requestId?: string;
|
|
77
|
+
commandId?: string;
|
|
78
|
+
detectedAtIso?: string;
|
|
79
|
+
hint?: string;
|
|
80
|
+
details?: string;
|
|
81
|
+
cause?: unknown;
|
|
82
|
+
}): IdempotencyInProgressError {
|
|
83
|
+
return IdempotencyInProgressError.detected(input);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static payloadMismatch(input: {
|
|
87
|
+
operation: string;
|
|
88
|
+
scope?: string;
|
|
89
|
+
entity?: string;
|
|
90
|
+
key?: string;
|
|
91
|
+
keyHash?: string;
|
|
92
|
+
keyPreview?: string;
|
|
93
|
+
incomingPayloadHash?: string;
|
|
94
|
+
existingPayloadHash?: string;
|
|
95
|
+
idempotencyRecordId?: string;
|
|
96
|
+
correlationId?: string;
|
|
97
|
+
requestId?: string;
|
|
98
|
+
commandId?: string;
|
|
99
|
+
detectedAtIso?: string;
|
|
100
|
+
hint?: string;
|
|
101
|
+
details?: string;
|
|
102
|
+
cause?: unknown;
|
|
103
|
+
}): IdempotencyPayloadMismatchError {
|
|
104
|
+
return IdempotencyPayloadMismatchError.detected(input);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static replayNotSupported(input: {
|
|
108
|
+
operation: string;
|
|
109
|
+
scope?: string;
|
|
110
|
+
entity?: string;
|
|
111
|
+
key?: string;
|
|
112
|
+
keyHash?: string;
|
|
113
|
+
keyPreview?: string;
|
|
114
|
+
idempotencyRecordId?: string;
|
|
115
|
+
correlationId?: string;
|
|
116
|
+
requestId?: string;
|
|
117
|
+
commandId?: string;
|
|
118
|
+
detectedAtIso?: string;
|
|
119
|
+
hint?: string;
|
|
120
|
+
details?: string;
|
|
121
|
+
cause?: unknown;
|
|
122
|
+
}): IdempotencyReplayNotSupportedError {
|
|
123
|
+
return IdempotencyReplayNotSupportedError.detected(input);
|
|
124
|
+
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
class IdempotencyKeyMissingError extends IdempotencyError {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
private constructor(input: {
|
|
129
|
+
metadata: Omit<IdempotencyErrorMetadata, "kind">;
|
|
130
|
+
cause?: unknown;
|
|
131
|
+
}) {
|
|
132
|
+
super({
|
|
133
|
+
message:
|
|
134
|
+
"Idempotency key/commandId missing for the requested operation",
|
|
135
|
+
code: ErrorCodes.idempotency.keyMissing,
|
|
136
|
+
kind: "key_missing",
|
|
137
|
+
metadata: input.metadata,
|
|
138
|
+
cause: input.cause,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
140
141
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
142
|
+
static detected(input: {
|
|
143
|
+
operation: string;
|
|
144
|
+
scope?: string;
|
|
145
|
+
entity?: string;
|
|
146
|
+
correlationId?: string;
|
|
147
|
+
requestId?: string;
|
|
148
|
+
commandId?: string;
|
|
149
|
+
detectedAtIso?: string;
|
|
150
|
+
hint?: string;
|
|
151
|
+
details?: string;
|
|
152
|
+
cause?: unknown;
|
|
153
|
+
}): IdempotencyKeyMissingError {
|
|
154
|
+
return new IdempotencyKeyMissingError({
|
|
155
|
+
cause: input.cause,
|
|
156
|
+
metadata: {
|
|
157
|
+
operation: input.operation,
|
|
158
|
+
scope: input.scope,
|
|
159
|
+
entity: input.entity,
|
|
160
|
+
correlationId: input.correlationId,
|
|
161
|
+
requestId: input.requestId,
|
|
162
|
+
commandId: input.commandId,
|
|
163
|
+
detectedAtIso: input.detectedAtIso,
|
|
164
|
+
hint:
|
|
165
|
+
input.hint ??
|
|
166
|
+
"Send a commandId/idempotency key to prevent duplicate processing.",
|
|
167
|
+
details: input.details,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
class IdempotencyInProgressError extends IdempotencyError {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
174
|
+
private constructor(input: {
|
|
175
|
+
metadata: Omit<IdempotencyErrorMetadata, "kind">;
|
|
176
|
+
cause?: unknown;
|
|
177
|
+
}) {
|
|
178
|
+
super({
|
|
179
|
+
message: "The same business intent is already being processed",
|
|
180
|
+
code: ErrorCodes.idempotency.inProgress,
|
|
181
|
+
kind: "in_progress",
|
|
182
|
+
metadata: input.metadata,
|
|
183
|
+
cause: input.cause,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
185
186
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
187
|
+
static detected(input: {
|
|
188
|
+
operation: string;
|
|
189
|
+
scope?: string;
|
|
190
|
+
entity?: string;
|
|
191
|
+
key?: string;
|
|
192
|
+
keyHash?: string;
|
|
193
|
+
keyPreview?: string;
|
|
194
|
+
idempotencyRecordId?: string;
|
|
195
|
+
correlationId?: string;
|
|
196
|
+
requestId?: string;
|
|
197
|
+
commandId?: string;
|
|
198
|
+
detectedAtIso?: string;
|
|
199
|
+
hint?: string;
|
|
200
|
+
details?: string;
|
|
201
|
+
cause?: unknown;
|
|
202
|
+
}): IdempotencyInProgressError {
|
|
203
|
+
const resolved = resolveKeyIdentity(
|
|
204
|
+
input.key,
|
|
205
|
+
input.keyHash,
|
|
206
|
+
input.keyPreview,
|
|
207
|
+
);
|
|
207
208
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
209
|
+
return new IdempotencyInProgressError({
|
|
210
|
+
cause: input.cause,
|
|
211
|
+
metadata: {
|
|
212
|
+
operation: input.operation,
|
|
213
|
+
scope: input.scope,
|
|
214
|
+
entity: input.entity,
|
|
215
|
+
keyHash: resolved.keyHash,
|
|
216
|
+
keyPreview: resolved.keyPreview,
|
|
217
|
+
idempotencyRecordId: input.idempotencyRecordId,
|
|
218
|
+
correlationId: input.correlationId,
|
|
219
|
+
requestId: input.requestId,
|
|
220
|
+
commandId: input.commandId,
|
|
221
|
+
detectedAtIso: input.detectedAtIso,
|
|
222
|
+
hint:
|
|
223
|
+
input.hint ??
|
|
224
|
+
"Wait for completion and retry using the same key.",
|
|
225
|
+
details: input.details,
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
}
|
|
226
229
|
}
|
|
227
230
|
|
|
228
231
|
class IdempotencyPayloadMismatchError extends IdempotencyError {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
232
|
+
private constructor(input: {
|
|
233
|
+
metadata: Omit<IdempotencyErrorMetadata, "kind">;
|
|
234
|
+
cause?: unknown;
|
|
235
|
+
}) {
|
|
236
|
+
super({
|
|
237
|
+
message: "The idempotency key was reused with a different payload",
|
|
238
|
+
code: ErrorCodes.idempotency.payloadMismatch,
|
|
239
|
+
kind: "payload_mismatch",
|
|
240
|
+
metadata: input.metadata,
|
|
241
|
+
cause: input.cause,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
241
244
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
245
|
+
static detected(input: {
|
|
246
|
+
operation: string;
|
|
247
|
+
scope?: string;
|
|
248
|
+
entity?: string;
|
|
249
|
+
key?: string;
|
|
250
|
+
keyHash?: string;
|
|
251
|
+
keyPreview?: string;
|
|
252
|
+
incomingPayloadHash?: string;
|
|
253
|
+
existingPayloadHash?: string;
|
|
254
|
+
idempotencyRecordId?: string;
|
|
255
|
+
correlationId?: string;
|
|
256
|
+
requestId?: string;
|
|
257
|
+
commandId?: string;
|
|
258
|
+
detectedAtIso?: string;
|
|
259
|
+
hint?: string;
|
|
260
|
+
details?: string;
|
|
261
|
+
cause?: unknown;
|
|
262
|
+
}): IdempotencyPayloadMismatchError {
|
|
263
|
+
const resolved = resolveKeyIdentity(
|
|
264
|
+
input.key,
|
|
265
|
+
input.keyHash,
|
|
266
|
+
input.keyPreview,
|
|
267
|
+
);
|
|
265
268
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
269
|
+
return new IdempotencyPayloadMismatchError({
|
|
270
|
+
cause: input.cause,
|
|
271
|
+
metadata: {
|
|
272
|
+
operation: input.operation,
|
|
273
|
+
scope: input.scope,
|
|
274
|
+
entity: input.entity,
|
|
275
|
+
keyHash: resolved.keyHash,
|
|
276
|
+
keyPreview: resolved.keyPreview,
|
|
277
|
+
incomingPayloadHash: input.incomingPayloadHash,
|
|
278
|
+
existingPayloadHash: input.existingPayloadHash,
|
|
279
|
+
idempotencyRecordId: input.idempotencyRecordId,
|
|
280
|
+
correlationId: input.correlationId,
|
|
281
|
+
requestId: input.requestId,
|
|
282
|
+
commandId: input.commandId,
|
|
283
|
+
detectedAtIso: input.detectedAtIso,
|
|
284
|
+
hint:
|
|
285
|
+
input.hint ??
|
|
286
|
+
"Use a new idempotency key for a new intent. The same key should only be reused for retries of the same payload.",
|
|
287
|
+
details: input.details,
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
}
|
|
288
291
|
}
|
|
289
292
|
|
|
290
293
|
class IdempotencyReplayNotSupportedError extends IdempotencyError {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
294
|
+
private constructor(input: {
|
|
295
|
+
metadata: Omit<IdempotencyErrorMetadata, "kind">;
|
|
296
|
+
cause?: unknown;
|
|
297
|
+
}) {
|
|
298
|
+
super({
|
|
299
|
+
message:
|
|
300
|
+
"Re-execution detected, but replay of the previous result is not implemented",
|
|
301
|
+
code: ErrorCodes.idempotency.replayNotSupported,
|
|
302
|
+
kind: "replay_not_supported",
|
|
303
|
+
metadata: input.metadata,
|
|
304
|
+
cause: input.cause,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
304
307
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
308
|
+
static detected(input: {
|
|
309
|
+
operation: string;
|
|
310
|
+
scope?: string;
|
|
311
|
+
entity?: string;
|
|
312
|
+
key?: string;
|
|
313
|
+
keyHash?: string;
|
|
314
|
+
keyPreview?: string;
|
|
315
|
+
idempotencyRecordId?: string;
|
|
316
|
+
correlationId?: string;
|
|
317
|
+
requestId?: string;
|
|
318
|
+
commandId?: string;
|
|
319
|
+
detectedAtIso?: string;
|
|
320
|
+
hint?: string;
|
|
321
|
+
details?: string;
|
|
322
|
+
cause?: unknown;
|
|
323
|
+
}): IdempotencyReplayNotSupportedError {
|
|
324
|
+
const resolved = resolveKeyIdentity(
|
|
325
|
+
input.key,
|
|
326
|
+
input.keyHash,
|
|
327
|
+
input.keyPreview,
|
|
328
|
+
);
|
|
326
329
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
330
|
+
return new IdempotencyReplayNotSupportedError({
|
|
331
|
+
cause: input.cause,
|
|
332
|
+
metadata: {
|
|
333
|
+
operation: input.operation,
|
|
334
|
+
scope: input.scope,
|
|
335
|
+
entity: input.entity,
|
|
336
|
+
keyHash: resolved.keyHash,
|
|
337
|
+
keyPreview: resolved.keyPreview,
|
|
338
|
+
idempotencyRecordId: input.idempotencyRecordId,
|
|
339
|
+
correlationId: input.correlationId,
|
|
340
|
+
requestId: input.requestId,
|
|
341
|
+
commandId: input.commandId,
|
|
342
|
+
detectedAtIso: input.detectedAtIso,
|
|
343
|
+
hint:
|
|
344
|
+
input.hint ??
|
|
345
|
+
"Try again later, or enable result replay for full idempotency.",
|
|
346
|
+
details: input.details,
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
}
|
|
347
350
|
}
|
|
348
351
|
|
|
349
352
|
function resolveKeyIdentity(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
+
key?: string,
|
|
354
|
+
keyHash?: string,
|
|
355
|
+
keyPreview?: string,
|
|
353
356
|
): { keyHash?: string; keyPreview?: string } {
|
|
354
|
-
|
|
355
|
-
|
|
357
|
+
const preview =
|
|
358
|
+
keyPreview ??
|
|
359
|
+
(key ? (key.length <= 8 ? key : key.slice(0, 8)) : undefined);
|
|
356
360
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
+
return {
|
|
362
|
+
keyHash: keyHash,
|
|
363
|
+
keyPreview: preview,
|
|
364
|
+
};
|
|
361
365
|
}
|
|
362
366
|
|
|
363
367
|
export {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
368
|
+
IdempotencyError,
|
|
369
|
+
IdempotencyKeyMissingError,
|
|
370
|
+
IdempotencyInProgressError,
|
|
371
|
+
IdempotencyPayloadMismatchError,
|
|
372
|
+
IdempotencyReplayNotSupportedError,
|
|
373
|
+
sha256Hex,
|
|
374
|
+
stableStringify,
|
|
375
|
+
payloadHash,
|
|
372
376
|
};
|