@xemahq/temporal-runtime 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -11
- package/dist/bin/controller-token-publisher.d.ts +3 -0
- package/dist/bin/controller-token-publisher.d.ts.map +1 -0
- package/dist/bin/controller-token-publisher.js +18 -0
- package/dist/bin/controller-token-publisher.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/access-token.d.ts +11 -0
- package/dist/lib/access-token.d.ts.map +1 -0
- package/dist/lib/access-token.js +30 -0
- package/dist/lib/access-token.js.map +1 -0
- package/dist/lib/base-temporal-client.service.d.ts +3 -2
- package/dist/lib/base-temporal-client.service.d.ts.map +1 -1
- package/dist/lib/base-temporal-client.service.js +5 -5
- package/dist/lib/base-temporal-client.service.js.map +1 -1
- package/dist/lib/biome-worker.d.ts +107 -0
- package/dist/lib/biome-worker.d.ts.map +1 -0
- package/dist/lib/biome-worker.js +348 -0
- package/dist/lib/biome-worker.js.map +1 -0
- package/dist/lib/bounded-retry.d.ts +22 -0
- package/dist/lib/bounded-retry.d.ts.map +1 -0
- package/dist/lib/bounded-retry.js +67 -0
- package/dist/lib/bounded-retry.js.map +1 -0
- package/dist/lib/client-credentials-token-source.d.ts +23 -0
- package/dist/lib/client-credentials-token-source.d.ts.map +1 -0
- package/dist/lib/client-credentials-token-source.js +108 -0
- package/dist/lib/client-credentials-token-source.js.map +1 -0
- package/dist/lib/connection.d.ts +48 -9
- package/dist/lib/connection.d.ts.map +1 -1
- package/dist/lib/connection.js +153 -41
- package/dist/lib/connection.js.map +1 -1
- package/dist/lib/controller-token-publisher.d.ts +51 -0
- package/dist/lib/controller-token-publisher.d.ts.map +1 -0
- package/dist/lib/controller-token-publisher.js +116 -0
- package/dist/lib/controller-token-publisher.js.map +1 -0
- package/dist/lib/fairness-constants.d.ts +4 -0
- package/dist/lib/fairness-constants.d.ts.map +1 -0
- package/dist/lib/fairness-constants.js +7 -0
- package/dist/lib/fairness-constants.js.map +1 -0
- package/dist/lib/fairness.d.ts +13 -0
- package/dist/lib/fairness.d.ts.map +1 -0
- package/dist/lib/fairness.js +56 -0
- package/dist/lib/fairness.js.map +1 -0
- package/dist/lib/nexus-constants.d.ts +8 -0
- package/dist/lib/nexus-constants.d.ts.map +1 -0
- package/dist/lib/nexus-constants.js +14 -0
- package/dist/lib/nexus-constants.js.map +1 -0
- package/dist/lib/nexus-contract.d.ts +43 -0
- package/dist/lib/nexus-contract.d.ts.map +1 -0
- package/dist/lib/nexus-contract.js +101 -0
- package/dist/lib/nexus-contract.js.map +1 -0
- package/dist/lib/nexus-handler.d.ts +32 -0
- package/dist/lib/nexus-handler.d.ts.map +1 -0
- package/dist/lib/nexus-handler.js +144 -0
- package/dist/lib/nexus-handler.js.map +1 -0
- package/dist/lib/nexus-workflow.d.ts +22 -0
- package/dist/lib/nexus-workflow.d.ts.map +1 -0
- package/dist/lib/nexus-workflow.js +74 -0
- package/dist/lib/nexus-workflow.js.map +1 -0
- package/dist/lib/org-erasure.d.ts +13 -0
- package/dist/lib/org-erasure.d.ts.map +1 -0
- package/dist/lib/org-erasure.js +68 -0
- package/dist/lib/org-erasure.js.map +1 -0
- package/dist/lib/proactive-token-refresher.d.ts +47 -0
- package/dist/lib/proactive-token-refresher.d.ts.map +1 -0
- package/dist/lib/proactive-token-refresher.js +147 -0
- package/dist/lib/proactive-token-refresher.js.map +1 -0
- package/dist/lib/search-attribute-constants.d.ts +3 -0
- package/dist/lib/search-attribute-constants.d.ts.map +1 -0
- package/dist/lib/search-attribute-constants.js +6 -0
- package/dist/lib/search-attribute-constants.js.map +1 -0
- package/dist/lib/search-attributes.d.ts +4 -18
- package/dist/lib/search-attributes.d.ts.map +1 -1
- package/dist/lib/search-attributes.js +33 -40
- package/dist/lib/search-attributes.js.map +1 -1
- package/dist/lib/standalone-activity.d.ts +23 -0
- package/dist/lib/standalone-activity.d.ts.map +1 -0
- package/dist/lib/standalone-activity.js +48 -0
- package/dist/lib/standalone-activity.js.map +1 -0
- package/dist/lib/versioned-worker.d.ts +26 -0
- package/dist/lib/versioned-worker.d.ts.map +1 -0
- package/dist/lib/versioned-worker.js +60 -0
- package/dist/lib/versioned-worker.js.map +1 -0
- package/dist/lib/worker-deployment-version.d.ts +8 -0
- package/dist/lib/worker-deployment-version.d.ts.map +1 -0
- package/dist/lib/worker-deployment-version.js +45 -0
- package/dist/lib/worker-deployment-version.js.map +1 -0
- package/dist/lib/worker.d.ts +8 -7
- package/dist/lib/worker.d.ts.map +1 -1
- package/dist/lib/worker.js +55 -37
- package/dist/lib/worker.js.map +1 -1
- package/dist/lib/workflow-interceptors/fairness-guard.d.ts +4 -0
- package/dist/lib/workflow-interceptors/fairness-guard.d.ts.map +1 -0
- package/dist/lib/workflow-interceptors/fairness-guard.js +79 -0
- package/dist/lib/workflow-interceptors/fairness-guard.js.map +1 -0
- package/dist/lib/workflow-interceptors/fairness-propagation.d.ts +3 -0
- package/dist/lib/workflow-interceptors/fairness-propagation.d.ts.map +1 -0
- package/dist/lib/workflow-interceptors/fairness-propagation.js +6 -0
- package/dist/lib/workflow-interceptors/fairness-propagation.js.map +1 -0
- package/dist/lib/workflow-interceptors/org-fairness-required.d.ts +3 -0
- package/dist/lib/workflow-interceptors/org-fairness-required.d.ts.map +1 -0
- package/dist/lib/workflow-interceptors/org-fairness-required.js +6 -0
- package/dist/lib/workflow-interceptors/org-fairness-required.js.map +1 -0
- package/dist/lib/workflow-interceptors/org-search-attribute.d.ts +3 -0
- package/dist/lib/workflow-interceptors/org-search-attribute.d.ts.map +1 -0
- package/dist/lib/workflow-interceptors/org-search-attribute.js +49 -0
- package/dist/lib/workflow-interceptors/org-search-attribute.js.map +1 -0
- package/dist/lib/workflow-purity.d.ts +27 -0
- package/dist/lib/workflow-purity.d.ts.map +1 -0
- package/dist/lib/workflow-purity.js +115 -0
- package/dist/lib/workflow-purity.js.map +1 -0
- package/package.json +33 -10
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NEXUS_OPERATION_TIMED_OUT = exports.NEXUS_ORG_MISSING = exports.NEXUS_CALLER_NOT_BOUND = exports.NEXUS_ENDPOINTS_NOT_DEFINED = exports.NEXUS_SERVICE_NOT_BOUND = exports.NEXUS_ENDPOINTS_DEFINE = void 0;
|
|
4
|
+
exports.nexusServiceKey = nexusServiceKey;
|
|
5
|
+
exports.NEXUS_ENDPOINTS_DEFINE = '__XEMA_NEXUS_ENDPOINTS__';
|
|
6
|
+
exports.NEXUS_SERVICE_NOT_BOUND = 'NEXUS_SERVICE_NOT_BOUND';
|
|
7
|
+
exports.NEXUS_ENDPOINTS_NOT_DEFINED = 'NEXUS_ENDPOINTS_NOT_DEFINED';
|
|
8
|
+
exports.NEXUS_CALLER_NOT_BOUND = 'NEXUS_CALLER_NOT_BOUND';
|
|
9
|
+
exports.NEXUS_ORG_MISSING = 'NEXUS_ORG_MISSING';
|
|
10
|
+
function nexusServiceKey(service, version) {
|
|
11
|
+
return `${service}@${version}`;
|
|
12
|
+
}
|
|
13
|
+
exports.NEXUS_OPERATION_TIMED_OUT = 'NEXUS_OPERATION_TIMED_OUT';
|
|
14
|
+
//# sourceMappingURL=nexus-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus-constants.js","sourceRoot":"","sources":["../../src/lib/nexus-constants.ts"],"names":[],"mappings":";;;AA8BA,0CAEC;AArBY,QAAA,sBAAsB,GAAG,0BAA0B,CAAC;AAOpD,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AAGpD,QAAA,2BAA2B,GAAG,6BAA6B,CAAC;AAG5D,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAGlD,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAGrD,SAAgB,eAAe,CAAC,OAAe,EAAE,OAAe;IAC9D,OAAO,GAAG,OAAO,IAAI,OAAO,EAAE,CAAC;AACjC,CAAC;AAMY,QAAA,yBAAyB,GAAG,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BiomeNexusOperationMode } from '@xemahq/contracts/biome';
|
|
2
|
+
import * as nexus from 'nexus-rpc';
|
|
3
|
+
export { BiomeNexusOperationMode };
|
|
4
|
+
export declare enum NexusOperationScope {
|
|
5
|
+
Org = "org",
|
|
6
|
+
Deployment = "deployment"
|
|
7
|
+
}
|
|
8
|
+
declare const operationTypes: unique symbol;
|
|
9
|
+
export interface XemaNexusOperation<I, O, M extends BiomeNexusOperationMode = BiomeNexusOperationMode> {
|
|
10
|
+
readonly mode: M;
|
|
11
|
+
readonly scope: NexusOperationScope;
|
|
12
|
+
readonly [operationTypes]?: {
|
|
13
|
+
readonly input: I;
|
|
14
|
+
readonly output: O;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface NexusOperationOptions {
|
|
18
|
+
readonly scope: NexusOperationScope;
|
|
19
|
+
}
|
|
20
|
+
export declare function syncOperation<I, O>(options: NexusOperationOptions): XemaNexusOperation<I, O, BiomeNexusOperationMode.Sync>;
|
|
21
|
+
export declare function asyncOperation<I, O>(options: NexusOperationOptions): XemaNexusOperation<I, O, BiomeNexusOperationMode.Async>;
|
|
22
|
+
export type XemaNexusOperationMap = Record<string, XemaNexusOperation<any, any>>;
|
|
23
|
+
export type NexusOperationInputOf<T> = T extends XemaNexusOperation<infer I, any> ? I : never;
|
|
24
|
+
export type NexusOperationOutputOf<T> = T extends XemaNexusOperation<any, infer O> ? O : never;
|
|
25
|
+
export type NexusDefinitionOperations<Ops extends XemaNexusOperationMap> = {
|
|
26
|
+
[K in keyof Ops & string]: nexus.OperationDefinition<NexusOperationInputOf<Ops[K]>, NexusOperationOutputOf<Ops[K]>>;
|
|
27
|
+
};
|
|
28
|
+
export interface XemaNexusContract<Ops extends XemaNexusOperationMap = XemaNexusOperationMap> {
|
|
29
|
+
readonly service: string;
|
|
30
|
+
readonly version: string;
|
|
31
|
+
readonly operations: Readonly<Ops>;
|
|
32
|
+
readonly definition: nexus.ServiceDefinition<NexusDefinitionOperations<Ops>>;
|
|
33
|
+
}
|
|
34
|
+
export declare class NexusContractError extends Error {
|
|
35
|
+
constructor(message: string);
|
|
36
|
+
}
|
|
37
|
+
export declare function nexusWireServiceName(service: string, version: string): string;
|
|
38
|
+
export declare function defineNexusContract<const Ops extends XemaNexusOperationMap>(spec: {
|
|
39
|
+
readonly service: string;
|
|
40
|
+
readonly version: string;
|
|
41
|
+
readonly operations: Ops;
|
|
42
|
+
}): XemaNexusContract<Ops>;
|
|
43
|
+
//# sourceMappingURL=nexus-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus-contract.d.ts","sourceRoot":"","sources":["../../src/lib/nexus-contract.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAMlE,OAAO,KAAK,KAAK,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAYnC,oBAAY,mBAAmB;IAC7B,GAAG,QAAQ;IACX,UAAU,eAAe;CAC1B;AAED,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAG5C,MAAM,WAAW,kBAAkB,CACjC,CAAC,EACD,CAAC,EACD,CAAC,SAAS,uBAAuB,GAAG,uBAAuB;IAE3D,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IAEpC,QAAQ,CAAC,CAAC,cAAc,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CAAC;CACvE;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAA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BAAyB,CAAC,GAAG,CAAC,CAAC,CAAC;CAC9E;AAED,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7E;AAQD,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,GAAG,SAAS,qBAAqB,EAAE,IAAI,EAAE;IACjF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC;CAC1B,GAAG,iBAAiB,CAAC,GAAG,CAAC,CA6CzB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.NexusContractError = exports.NexusOperationScope = exports.BiomeNexusOperationMode = void 0;
|
|
37
|
+
exports.syncOperation = syncOperation;
|
|
38
|
+
exports.asyncOperation = asyncOperation;
|
|
39
|
+
exports.nexusWireServiceName = nexusWireServiceName;
|
|
40
|
+
exports.defineNexusContract = defineNexusContract;
|
|
41
|
+
const biome_1 = require("@xemahq/contracts/biome");
|
|
42
|
+
Object.defineProperty(exports, "BiomeNexusOperationMode", { enumerable: true, get: function () { return biome_1.BiomeNexusOperationMode; } });
|
|
43
|
+
const workflow_1 = require("@xemahq/contracts/workflow");
|
|
44
|
+
const nexus = __importStar(require("nexus-rpc"));
|
|
45
|
+
var NexusOperationScope;
|
|
46
|
+
(function (NexusOperationScope) {
|
|
47
|
+
NexusOperationScope["Org"] = "org";
|
|
48
|
+
NexusOperationScope["Deployment"] = "deployment";
|
|
49
|
+
})(NexusOperationScope || (exports.NexusOperationScope = NexusOperationScope = {}));
|
|
50
|
+
function syncOperation(options) {
|
|
51
|
+
return Object.freeze({ mode: biome_1.BiomeNexusOperationMode.Sync, scope: options.scope });
|
|
52
|
+
}
|
|
53
|
+
function asyncOperation(options) {
|
|
54
|
+
return Object.freeze({ mode: biome_1.BiomeNexusOperationMode.Async, scope: options.scope });
|
|
55
|
+
}
|
|
56
|
+
class NexusContractError extends Error {
|
|
57
|
+
constructor(message) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.name = 'NexusContractError';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.NexusContractError = NexusContractError;
|
|
63
|
+
function nexusWireServiceName(service, version) {
|
|
64
|
+
return `${service}.${version}`;
|
|
65
|
+
}
|
|
66
|
+
function defineNexusContract(spec) {
|
|
67
|
+
const where = `nexus contract ${spec.service}@${spec.version}`;
|
|
68
|
+
for (const [what, schema, value] of [
|
|
69
|
+
['service', workflow_1.NexusServiceNameSchema, spec.service],
|
|
70
|
+
['version', workflow_1.NexusServiceVersionSchema, spec.version],
|
|
71
|
+
]) {
|
|
72
|
+
const parsed = schema.safeParse(value);
|
|
73
|
+
if (!parsed.success) {
|
|
74
|
+
throw new NexusContractError(`${where}: ${what} ${JSON.stringify(value)} is invalid: ${parsed.error.issues.map((i) => i.message).join('; ')}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const names = Object.keys(spec.operations);
|
|
78
|
+
if (names.length === 0) {
|
|
79
|
+
throw new NexusContractError(`${where}: a contract with no operations states nothing.`);
|
|
80
|
+
}
|
|
81
|
+
const partial = {};
|
|
82
|
+
for (const name of names) {
|
|
83
|
+
if (!workflow_1.NexusOperationNameSchema.safeParse(name).success) {
|
|
84
|
+
throw new NexusContractError(`${where}: operation ${JSON.stringify(name)} must be lower camelCase.`);
|
|
85
|
+
}
|
|
86
|
+
const op = spec.operations[name];
|
|
87
|
+
if (!Object.values(biome_1.BiomeNexusOperationMode).includes(op?.mode) ||
|
|
88
|
+
!Object.values(NexusOperationScope).includes(op?.scope)) {
|
|
89
|
+
throw new NexusContractError(`${where}: operation ${name} must be built with syncOperation() or asyncOperation().`);
|
|
90
|
+
}
|
|
91
|
+
partial[name] = nexus.operation({ name });
|
|
92
|
+
}
|
|
93
|
+
const definition = nexus.service(nexusWireServiceName(spec.service, spec.version), partial);
|
|
94
|
+
return Object.freeze({
|
|
95
|
+
service: spec.service,
|
|
96
|
+
version: spec.version,
|
|
97
|
+
operations: Object.freeze({ ...spec.operations }),
|
|
98
|
+
definition,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=nexus-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus-contract.js","sourceRoot":"","sources":["../../src/lib/nexus-contract.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,sCAIC;AAOD,wCAIC;AA6CD,oDAEC;AAQD,kDAiDC;AAtKD,mDAAkE;AAQzD,wGARA,+BAAuB,OAQA;AAPhC,yDAIoC;AACpC,iDAAmC;AAcnC,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,kCAAW,CAAA;IACX,gDAAyB,CAAA;AAC3B,CAAC,EAHW,mBAAmB,mCAAnB,mBAAmB,QAG9B;AAwBD,SAAgB,aAAa,CAC3B,OAA8B;IAE9B,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,+BAAuB,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AACrF,CAAC;AAOD,SAAgB,cAAc,CAC5B,OAA8B;IAE9B,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,+BAAuB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AACtF,CAAC;AAqCD,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC;AAGD,SAAgB,oBAAoB,CAAC,OAAe,EAAE,OAAe;IACnE,OAAO,GAAG,OAAO,IAAI,OAAO,EAAE,CAAC;AACjC,CAAC;AAQD,SAAgB,mBAAmB,CAA0C,IAI5E;IACC,MAAM,KAAK,GAAG,kBAAkB,IAAI,CAAC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AM,CAAC,MAAM,CAAC,+BAAuB,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;YAC1D,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,EACvD,CAAC;YACD,MAAM,IAAI,kBAAkB,CAC1B,GAAG,KAAK,eAAe,IAAI,0DAA0D,CACtF,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,SAAS,CAAmB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAC9B,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,EAChD,OAAO,CAC8D,CAAC;IACxE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACjD,UAAU;KACX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type WorkflowHandle, type WorkflowStartOptions as NexusWorkflowStartOptions } from '@temporalio/nexus';
|
|
2
|
+
import * as nexus from 'nexus-rpc';
|
|
3
|
+
import { BiomeNexusOperationMode, NexusOperationScope, type NexusOperationInputOf, type NexusOperationOutputOf, type XemaNexusContract, type XemaNexusOperation, type XemaNexusOperationMap } from './nexus-contract';
|
|
4
|
+
import type { PlatformNexusServiceHandler } from './versioned-worker';
|
|
5
|
+
import type { Priority, Workflow, WorkflowResultType } from '@temporalio/common';
|
|
6
|
+
export type NexusOrgWorkflowStartOptions<T extends Workflow> = Omit<NexusWorkflowStartOptions<T>, 'priority' | 'searchAttributes' | 'typedSearchAttributes'> & {
|
|
7
|
+
readonly priority?: Omit<Priority, 'fairnessKey'>;
|
|
8
|
+
};
|
|
9
|
+
export interface XemaNexusOperationContext<S extends NexusOperationScope = NexusOperationScope> {
|
|
10
|
+
readonly orgId: S extends NexusOperationScope.Org ? string : string | undefined;
|
|
11
|
+
readonly callerNamespace: string;
|
|
12
|
+
readonly nexus: nexus.StartOperationContext;
|
|
13
|
+
startWorkflow<T extends Workflow>(workflowTypeOrFunc: string | T, options: NexusOrgWorkflowStartOptions<T>): Promise<WorkflowHandle<WorkflowResultType<T>>>;
|
|
14
|
+
}
|
|
15
|
+
type ScopeOf<Op> = Op extends XemaNexusOperation<any, any> ? Op['scope'] : never;
|
|
16
|
+
export type XemaNexusOperationImpl<Op> = Op extends XemaNexusOperation<infer I, infer O, BiomeNexusOperationMode.Async> ? (ctx: XemaNexusOperationContext<ScopeOf<Op>>, input: I) => Promise<WorkflowHandle<O>> : Op extends XemaNexusOperation<infer I, infer O, BiomeNexusOperationMode.Sync> ? (ctx: XemaNexusOperationContext<ScopeOf<Op>>, input: I) => Promise<O> : never;
|
|
17
|
+
export type XemaNexusServiceImpl<Ops extends XemaNexusOperationMap> = {
|
|
18
|
+
readonly [K in keyof Ops & string]: XemaNexusOperationImpl<Ops[K]>;
|
|
19
|
+
};
|
|
20
|
+
export interface NexusCallerPolicy {
|
|
21
|
+
readonly allowedCallerNamespaces: ReadonlySet<string>;
|
|
22
|
+
}
|
|
23
|
+
export interface XemaNexusServiceImplementation {
|
|
24
|
+
readonly service: string;
|
|
25
|
+
readonly version: string;
|
|
26
|
+
readonly operations: ReadonlyMap<string, BiomeNexusOperationMode>;
|
|
27
|
+
bind(policy: NexusCallerPolicy): PlatformNexusServiceHandler;
|
|
28
|
+
}
|
|
29
|
+
export declare function callerNamespaceOf(links: readonly nexus.Link[]): string | undefined;
|
|
30
|
+
export declare function nexusHandlerFor<Ops extends XemaNexusOperationMap>(contract: XemaNexusContract<Ops>, impl: XemaNexusServiceImpl<Ops>): XemaNexusServiceImplementation;
|
|
31
|
+
export type { NexusOperationInputOf, NexusOperationOutputOf };
|
|
32
|
+
//# sourceMappingURL=nexus-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus-handler.d.ts","sourceRoot":"","sources":["../../src/lib/nexus-handler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,oBAAoB,IAAI,yBAAyB,EACvD,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,WAAW,CAAC;AAKnC,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAOjF,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,QAAQ,IAAI,IAAI,CACjE,yBAAyB,CAAC,CAAC,CAAC,EAC5B,UAAU,GAAG,kBAAkB,GAAG,uBAAuB,CAC1D,GAAG;IACF,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;CACnD,CAAC;AAGF,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,mBAAmB,GAAG,mBAAmB;IAE5F,QAAQ,CAAC,KAAK,EAAE,CAAC,SAAS,mBAAmB,CAAC,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAEhF,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,qBAAqB,CAAC;IAQ5C,aAAa,CAAC,CAAC,SAAS,QAAQ,EAC9B,kBAAkB,EAAE,MA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E,uBAAuB,CAAC,CAAC;IAElE,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,2BAA2B,CAAC;CAC9D;AAWD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,KAAK,CAAC,IAAI,EAAE,GAAG,MAAM,GAAG,SAAS,CAWlF;AA2ED,wBAAgB,eAAe,CAAC,GAAG,SAAS,qBAAqB,EAC/D,QAAQ,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAChC,IAAI,EAAE,oBAAoB,CAAC,GAAG,CAAC,GAC9B,8BAA8B,CA6ChC;AAED,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.callerNamespaceOf = callerNamespaceOf;
|
|
37
|
+
exports.nexusHandlerFor = nexusHandlerFor;
|
|
38
|
+
const nexus_1 = require("@temporalio/nexus");
|
|
39
|
+
const nexus = __importStar(require("nexus-rpc"));
|
|
40
|
+
const fairness_1 = require("./fairness");
|
|
41
|
+
const fairness_constants_1 = require("./fairness-constants");
|
|
42
|
+
const nexus_constants_1 = require("./nexus-constants");
|
|
43
|
+
const nexus_contract_1 = require("./nexus-contract");
|
|
44
|
+
const search_attribute_constants_1 = require("./search-attribute-constants");
|
|
45
|
+
const WORKFLOW_EVENT_LINK_TYPE = 'temporal.api.common.v1.Link.WorkflowEvent';
|
|
46
|
+
const WORKFLOW_EVENT_LINK_PATH = /^\/namespaces\/([^/]+)\/workflows\//;
|
|
47
|
+
function refuse(code, message) {
|
|
48
|
+
return new nexus.HandlerError(code === nexus_constants_1.NEXUS_CALLER_NOT_BOUND ? 'UNAUTHORIZED' : 'BAD_REQUEST', `[${code}] ${message}`, { retryableOverride: false });
|
|
49
|
+
}
|
|
50
|
+
function callerNamespaceOf(links) {
|
|
51
|
+
for (const link of links) {
|
|
52
|
+
if (link.type !== WORKFLOW_EVENT_LINK_TYPE || link.url.protocol !== 'temporal:') {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const match = WORKFLOW_EVENT_LINK_PATH.exec(link.url.pathname);
|
|
56
|
+
if (match?.[1] !== undefined) {
|
|
57
|
+
return decodeURIComponent(match[1]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
function headerValue(headers, name) {
|
|
63
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
64
|
+
if (key.toLowerCase() === name)
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
function admit(where, op, policy, ctx) {
|
|
70
|
+
const callerNamespace = callerNamespaceOf(ctx.inboundLinks);
|
|
71
|
+
if (callerNamespace === undefined) {
|
|
72
|
+
throw refuse(nexus_constants_1.NEXUS_CALLER_NOT_BOUND, `${where}: the request carries no calling-workflow link, so its caller cannot be verified.`);
|
|
73
|
+
}
|
|
74
|
+
if (!policy.allowedCallerNamespaces.has(callerNamespace)) {
|
|
75
|
+
throw refuse(nexus_constants_1.NEXUS_CALLER_NOT_BOUND, `${where}: namespace ${callerNamespace} is not bound to this service by the distribution lock.`);
|
|
76
|
+
}
|
|
77
|
+
const rawOrg = headerValue(ctx.headers, fairness_constants_1.XEMA_NEXUS_ORG_HEADER);
|
|
78
|
+
let orgId;
|
|
79
|
+
if (rawOrg !== undefined && rawOrg.length > 0) {
|
|
80
|
+
try {
|
|
81
|
+
orgId = (0, fairness_1.orgFairnessKey)(rawOrg);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw refuse(nexus_constants_1.NEXUS_ORG_MISSING, `${where}: ${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (op.scope === nexus_contract_1.NexusOperationScope.Org && orgId === undefined) {
|
|
88
|
+
throw refuse(nexus_constants_1.NEXUS_ORG_MISSING, `${where} is org-scoped and the request names no org (${fairness_constants_1.XEMA_NEXUS_ORG_HEADER}). ` +
|
|
89
|
+
'Call it from a run started with startWorkflowForOrg.');
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
orgId,
|
|
93
|
+
callerNamespace,
|
|
94
|
+
nexus: ctx,
|
|
95
|
+
startWorkflow(workflowTypeOrFunc, options) {
|
|
96
|
+
const supplied = options.priority;
|
|
97
|
+
if (supplied?.fairnessKey !== undefined) {
|
|
98
|
+
throw new Error(`${where}: priority.fairnessKey is derived from the caller's org and may not be supplied.`);
|
|
99
|
+
}
|
|
100
|
+
return (0, nexus_1.startWorkflow)(ctx, workflowTypeOrFunc, {
|
|
101
|
+
...options,
|
|
102
|
+
...(orgId !== undefined
|
|
103
|
+
? {
|
|
104
|
+
priority: { ...supplied, fairnessKey: orgId },
|
|
105
|
+
searchAttributes: { [search_attribute_constants_1.SEARCH_ATTR_ORG_ID]: [orgId] },
|
|
106
|
+
}
|
|
107
|
+
: {}),
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function nexusHandlerFor(contract, impl) {
|
|
113
|
+
const names = Object.keys(contract.operations);
|
|
114
|
+
const implemented = Object.keys(impl);
|
|
115
|
+
const missing = names.filter((n) => typeof impl[n] !== 'function');
|
|
116
|
+
const extra = implemented.filter((n) => !names.includes(n));
|
|
117
|
+
if (missing.length > 0 || extra.length > 0) {
|
|
118
|
+
throw new Error(`nexusHandlerFor(${contract.service}@${contract.version}): implementations must match the contract` +
|
|
119
|
+
(missing.length > 0 ? `; missing: ${missing.join(', ')}` : '') +
|
|
120
|
+
(extra.length > 0 ? `; not in the contract: ${extra.join(', ')}` : '') +
|
|
121
|
+
'.');
|
|
122
|
+
}
|
|
123
|
+
const operations = new Map(names.map((n) => [n, contract.operations[n].mode]));
|
|
124
|
+
function bind(policy) {
|
|
125
|
+
const handlers = {};
|
|
126
|
+
for (const name of names) {
|
|
127
|
+
const op = contract.operations[name];
|
|
128
|
+
const where = `${contract.service}@${contract.version}.${name}`;
|
|
129
|
+
const run = impl[name];
|
|
130
|
+
handlers[name] =
|
|
131
|
+
op.mode === nexus_contract_1.BiomeNexusOperationMode.Async
|
|
132
|
+
? new nexus_1.WorkflowRunOperationHandler((ctx, input) => run(admit(where, op, policy, ctx), input))
|
|
133
|
+
: (ctx, input) => run(admit(where, op, policy, ctx), input);
|
|
134
|
+
}
|
|
135
|
+
return nexus.serviceHandler(contract.definition, handlers);
|
|
136
|
+
}
|
|
137
|
+
return Object.freeze({
|
|
138
|
+
service: contract.service,
|
|
139
|
+
version: contract.version,
|
|
140
|
+
operations,
|
|
141
|
+
bind,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=nexus-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus-handler.js","sourceRoot":"","sources":["../../src/lib/nexus-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,8CAWC;AA2ED,0CAgDC;AAvOD,6CAK2B;AAC3B,iDAAmC;AAEnC,yCAA4C;AAC5C,6DAA6D;AAC7D,uDAA8E;AAC9E,qDAQ0B;AAC1B,6EAAkE;AAMlE,MAAM,wBAAwB,GAAG,2CAA2C,CAAC;AAC7E,MAAM,wBAAwB,GAAG,qCAAqC,CAAC;AA6DvE,SAAS,MAAM,CAAC,IAAY,EAAE,OAAe;IAC3C,OAAO,IAAI,KAAK,CAAC,YAAY,CAC3B,IAAI,KAAK,wCAAsB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,EAChE,IAAI,IAAI,KAAK,OAAO,EAAE,EACtB,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC;AACJ,CAAC;AAGD,SAAgB,iBAAiB,CAAC,KAA4B;IAC5D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,wBAAwB,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YAChF,SAAS;QACX,CAAC;QACD,MAAM,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,Q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;gBACZ,EAAE,CAAC,IAAI,KAAK,wCAAuB,CAAC,KAAK;oBACvC,CAAC,CAAC,IAAI,mCAA2B,CAC7B,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,CAAqC,CAC9F;oBACH,CAAC,CAAC,CAAC,GAAgC,EAAE,KAAc,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,KAAK,CAAC,cAAc,CACzB,QAAQ,CAAC,UAAU,EACnB,QAA0C,CACD,CAAC;IAC9C,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,UAAU;QACV,IAAI;KACL,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ApplicationFailure, type TimeoutType } from '@temporalio/common';
|
|
2
|
+
import { type StartNexusOperationOptions } from '@temporalio/workflow';
|
|
3
|
+
import type { NexusOperationInputOf, NexusOperationOutputOf, XemaNexusContract, XemaNexusOperationMap } from './nexus-contract';
|
|
4
|
+
export declare class NexusOperationTimedOut extends ApplicationFailure {
|
|
5
|
+
readonly service: string;
|
|
6
|
+
readonly version: string;
|
|
7
|
+
readonly operation: string;
|
|
8
|
+
readonly timeoutType: TimeoutType;
|
|
9
|
+
constructor(service: string, version: string, operation: string, timeoutType: TimeoutType, cause: Error);
|
|
10
|
+
}
|
|
11
|
+
export type XemaNexusCallOptions = Partial<StartNexusOperationOptions>;
|
|
12
|
+
export interface XemaNexusOperationHandle<O> {
|
|
13
|
+
readonly operation: string;
|
|
14
|
+
readonly token: string | undefined;
|
|
15
|
+
result(): Promise<O>;
|
|
16
|
+
}
|
|
17
|
+
export interface XemaNexusClient<Ops extends XemaNexusOperationMap> {
|
|
18
|
+
executeOperation<K extends keyof Ops & string>(operation: K, input: NexusOperationInputOf<Ops[K]>, options?: XemaNexusCallOptions): Promise<NexusOperationOutputOf<Ops[K]>>;
|
|
19
|
+
startOperation<K extends keyof Ops & string>(operation: K, input: NexusOperationInputOf<Ops[K]>, options?: XemaNexusCallOptions): Promise<XemaNexusOperationHandle<NexusOperationOutputOf<Ops[K]>>>;
|
|
20
|
+
}
|
|
21
|
+
export declare function nexusClientFor<Ops extends XemaNexusOperationMap>(contract: XemaNexusContract<Ops>): XemaNexusClient<Ops>;
|
|
22
|
+
//# sourceMappingURL=nexus-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus-workflow.d.ts","sourceRoot":"","sources":["../../src/lib/nexus-workflow.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,EAGlB,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,sBAAsB,CAAC;AAS9B,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAU1B,qBAAa,sBAAuB,SAAQ,kBAAkB;IAE1D,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM;IAC1B,QAAQ,CAAC,WAAW,EAAE,WAAW;gBAHxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,EACjC,KAAK,EAAE,KAAK;CAYf;AAGD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAEvE,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;CACtB;AAGD,MAAM,WAAW,eAAe,CAAC,GAAG,SAAS,qBAAqB;IAChE,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,MAAM,EAC3C,SAAS,EAAE,CAAC,EACZ,KAAK,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACpC,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,MAAM,EACzC,SAAS,EAAE,CAAC,EACZ,KAAK,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACpC,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACtE;AAsCD,wBAAgB,cAAc,CAAC,GAAG,SAAS,qBAAqB,EAC9D,QAAQ,EAAE,iBAAiB,CAAC,GAAG,CAAC,GAC/B,eAAe,CAAC,GAAG,CAAC,CA4DtB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NexusOperationTimedOut = void 0;
|
|
4
|
+
exports.nexusClientFor = nexusClientFor;
|
|
5
|
+
const common_1 = require("@temporalio/common");
|
|
6
|
+
const workflow_1 = require("@temporalio/workflow");
|
|
7
|
+
const nexus_constants_1 = require("./nexus-constants");
|
|
8
|
+
class NexusOperationTimedOut extends common_1.ApplicationFailure {
|
|
9
|
+
service;
|
|
10
|
+
version;
|
|
11
|
+
operation;
|
|
12
|
+
timeoutType;
|
|
13
|
+
constructor(service, version, operation, timeoutType, cause) {
|
|
14
|
+
super(`Nexus operation ${service}@${version}.${operation} timed out (${String(timeoutType)}).`, nexus_constants_1.NEXUS_OPERATION_TIMED_OUT, true, undefined, cause);
|
|
15
|
+
this.service = service;
|
|
16
|
+
this.version = version;
|
|
17
|
+
this.operation = operation;
|
|
18
|
+
this.timeoutType = timeoutType;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.NexusOperationTimedOut = NexusOperationTimedOut;
|
|
22
|
+
function timeoutOf(error) {
|
|
23
|
+
if (!(error instanceof common_1.NexusOperationFailure))
|
|
24
|
+
return undefined;
|
|
25
|
+
let cause = error.cause;
|
|
26
|
+
while (cause instanceof Error) {
|
|
27
|
+
if (cause instanceof common_1.TimeoutFailure)
|
|
28
|
+
return cause;
|
|
29
|
+
cause = cause.cause;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
function boundEndpoints() {
|
|
34
|
+
return typeof __XEMA_NEXUS_ENDPOINTS__ === 'undefined'
|
|
35
|
+
? undefined
|
|
36
|
+
: __XEMA_NEXUS_ENDPOINTS__;
|
|
37
|
+
}
|
|
38
|
+
function nexusClientFor(contract) {
|
|
39
|
+
const endpoints = boundEndpoints();
|
|
40
|
+
const key = (0, nexus_constants_1.nexusServiceKey)(contract.service, contract.version);
|
|
41
|
+
if (endpoints === undefined) {
|
|
42
|
+
throw common_1.ApplicationFailure.nonRetryable(`nexusClientFor(${key}): this workflow bundle carries no Nexus endpoints; ` +
|
|
43
|
+
'it was not built by composeBiomeWorkers, which resolves them from the lock.', nexus_constants_1.NEXUS_ENDPOINTS_NOT_DEFINED);
|
|
44
|
+
}
|
|
45
|
+
const endpoint = endpoints[key];
|
|
46
|
+
if (endpoint === undefined) {
|
|
47
|
+
throw common_1.ApplicationFailure.nonRetryable(`nexusClientFor(${key}): this component's manifest does not require ${key}, ` +
|
|
48
|
+
'or requires it optionally and no biome in this edition provides it. ' +
|
|
49
|
+
`Bound: ${Object.keys(endpoints).sort().join(', ') || 'none'}.`, nexus_constants_1.NEXUS_SERVICE_NOT_BOUND);
|
|
50
|
+
}
|
|
51
|
+
const client = (0, workflow_1.createNexusServiceClient)({ endpoint, service: contract.definition });
|
|
52
|
+
const typed = (operation, pending) => pending.catch((error) => {
|
|
53
|
+
const timeout = timeoutOf(error);
|
|
54
|
+
throw timeout === undefined
|
|
55
|
+
? error
|
|
56
|
+
: new NexusOperationTimedOut(contract.service, contract.version, operation, timeout.timeoutType, error);
|
|
57
|
+
});
|
|
58
|
+
const raw = client;
|
|
59
|
+
async function startOperation(operation, input, options) {
|
|
60
|
+
const handle = await typed(operation, raw.startOperation(operation, input, options));
|
|
61
|
+
return {
|
|
62
|
+
operation,
|
|
63
|
+
token: handle.token,
|
|
64
|
+
result: () => typed(operation, handle.result()),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
startOperation,
|
|
69
|
+
async executeOperation(operation, input, options) {
|
|
70
|
+
return (await startOperation(operation, input, options)).result();
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=nexus-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nexus-workflow.js","sourceRoot":"","sources":["../../src/lib/nexus-workflow.ts"],"names":[],"mappings":";;;AAqHA,wCA8DC;AAhLD,+CAK4B;AAC5B,mDAG8B;AAE9B,uDAK2B;AAiB3B,MAAa,sBAAuB,SAAQ,2BAAkB;IAEjD;IACA;IACA;IACA;IAJX,YACW,OAAe,EACf,OAAe,EACf,SAAiB,EACjB,WAAwB,EACjC,KAAY;QAEZ,KAAK,CACH,mBAAmB,OAAO,IAAI,OAAO,IAAI,SAAS,eAAe,MAAM,CAAC,WAAW,CAAC,IAAI,EACxF,2CAAyB,EACzB,IAAI,EACJ,SAAS,EACT,KAAK,CACN,CAAC;QAZO,YAAO,GAAP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io/client';
|
|
2
|
+
export interface EraseOrgWorkflowExecutionsOptions {
|
|
3
|
+
readonly orgId: string;
|
|
4
|
+
readonly reason: string;
|
|
5
|
+
readonly deadlineMs?: number;
|
|
6
|
+
readonly passIntervalMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface EraseOrgWorkflowExecutionsResult {
|
|
9
|
+
readonly erased: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function orgWorkflowExecutionsQuery(orgId: string): string;
|
|
12
|
+
export declare function eraseOrgWorkflowExecutions(client: Client, options: EraseOrgWorkflowExecutionsOptions): Promise<EraseOrgWorkflowExecutionsResult>;
|
|
13
|
+
//# sourceMappingURL=org-erasure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"org-erasure.d.ts","sourceRoot":"","sources":["../../src/lib/org-erasure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAuBxE,MAAM,WAAW,iCAAiC;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,gCAAgC;IAE/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAQD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhE;AAQD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iCAAiC,GACzC,OAAO,CAAC,gCAAgC,CAAC,CA0C3C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.orgWorkflowExecutionsQuery = orgWorkflowExecutionsQuery;
|
|
4
|
+
exports.eraseOrgWorkflowExecutions = eraseOrgWorkflowExecutions;
|
|
5
|
+
const client_1 = require("@temporalio/client");
|
|
6
|
+
const fairness_1 = require("./fairness");
|
|
7
|
+
const search_attribute_constants_1 = require("./search-attribute-constants");
|
|
8
|
+
const DEFAULT_DEADLINE_MS = 5 * 60_000;
|
|
9
|
+
const DEFAULT_PASS_INTERVAL_MS = 1_000;
|
|
10
|
+
const GRPC_NOT_FOUND = 5;
|
|
11
|
+
function orgWorkflowExecutionsQuery(orgId) {
|
|
12
|
+
const id = (0, fairness_1.orgFairnessKey)(orgId);
|
|
13
|
+
if (/['"\\]/.test(id)) {
|
|
14
|
+
throw new Error(`orgWorkflowExecutionsQuery: org id ${JSON.stringify(orgId)} contains a quote or backslash.`);
|
|
15
|
+
}
|
|
16
|
+
return `${search_attribute_constants_1.SEARCH_ATTR_ORG_ID} = '${id}'`;
|
|
17
|
+
}
|
|
18
|
+
function isNotFound(error) {
|
|
19
|
+
if (error instanceof client_1.WorkflowNotFoundError)
|
|
20
|
+
return true;
|
|
21
|
+
const code = error?.code;
|
|
22
|
+
return code === GRPC_NOT_FOUND;
|
|
23
|
+
}
|
|
24
|
+
async function eraseOrgWorkflowExecutions(client, options) {
|
|
25
|
+
const query = orgWorkflowExecutionsQuery(options.orgId);
|
|
26
|
+
const namespace = client.options.namespace;
|
|
27
|
+
const deadline = Date.now() + (options.deadlineMs ?? DEFAULT_DEADLINE_MS);
|
|
28
|
+
const interval = options.passIntervalMs ?? DEFAULT_PASS_INTERVAL_MS;
|
|
29
|
+
const erased = new Set();
|
|
30
|
+
for (;;) {
|
|
31
|
+
let found = 0;
|
|
32
|
+
for await (const execution of client.workflow.list({ query })) {
|
|
33
|
+
found += 1;
|
|
34
|
+
const { workflowId, runId } = execution;
|
|
35
|
+
if (execution.status.name === 'RUNNING') {
|
|
36
|
+
try {
|
|
37
|
+
await client.workflow
|
|
38
|
+
.getHandle(workflowId, runId)
|
|
39
|
+
.terminate(options.reason);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (!isNotFound(error))
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await client.workflowService.deleteWorkflowExecution({
|
|
48
|
+
namespace,
|
|
49
|
+
workflowExecution: { workflowId, runId },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!isNotFound(error))
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
erased.add(`${workflowId}/${runId}`);
|
|
57
|
+
}
|
|
58
|
+
if (found === 0) {
|
|
59
|
+
return { erased: erased.size };
|
|
60
|
+
}
|
|
61
|
+
if (Date.now() > deadline) {
|
|
62
|
+
throw new Error(`eraseOrgWorkflowExecutions: org ${options.orgId} still has executions in ` +
|
|
63
|
+
`namespace '${namespace}' after the erasure deadline; the erasure did not complete.`);
|
|
64
|
+
}
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=org-erasure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"org-erasure.js","sourceRoot":"","sources":["../../src/lib/org-erasure.ts"],"names":[],"mappings":";;AA4CA,gEAUC;AAQD,gEA6CC;AA3GD,+CAAwE;AAExE,yCAA4C;AAC5C,6EAAkE;AAmClE,MAAM,mBAAmB,GAAG,CAAC,GAAG,MAAM,CAAC;AACvC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAEvC,MAAM,cAAc,GAAG,CAAC,CAAC;AAGzB,SAAgB,0BAA0B,CAAC,KAAa;IAGtD,MAAM,EAAE,GAAG,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC;IACjC,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,sCAAsC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,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CAAC;wBAAE,MAAM,KAAK,CAAC;gBACtC,CAAC;YACH,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,eAAe,CAAC,uBAAuB,CAAC;oBACnD,SAAS;oBACT,iBAAiB,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;iBACzC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;oBAAE,MAAM,KAAK,CAAC;YACtC,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,IAAI,KAAK,EAAE,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACjC,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CACb,mCAAmC,OAAO,CAAC,KAAK,2BAA2B;gBACzE,cAAc,SAAS,6DAA6D,CACvF,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AccessToken, AccessTokenSource } from './access-token';
|
|
2
|
+
import { type BoundedRetryPolicy, type RetryClock } from './bounded-retry';
|
|
3
|
+
export type AccessTokenListener = (token: AccessToken) => void | Promise<void>;
|
|
4
|
+
export interface TokenRefresherLogger {
|
|
5
|
+
log(message: string): void;
|
|
6
|
+
warn(message: string): void;
|
|
7
|
+
error(message: string): void;
|
|
8
|
+
}
|
|
9
|
+
export interface ProactiveTokenRefresherOptions {
|
|
10
|
+
readonly source: AccessTokenSource;
|
|
11
|
+
readonly description: string;
|
|
12
|
+
readonly refreshAtFraction?: number;
|
|
13
|
+
readonly startupRetry?: BoundedRetryPolicy;
|
|
14
|
+
readonly refreshRetryInitialDelayMs?: number;
|
|
15
|
+
readonly refreshRetryMaxDelayMs?: number;
|
|
16
|
+
readonly onFatal?: (error: Error) => void;
|
|
17
|
+
readonly logger?: TokenRefresherLogger;
|
|
18
|
+
readonly clock?: RetryClock;
|
|
19
|
+
}
|
|
20
|
+
export declare class TokenRefreshFatalError extends Error {
|
|
21
|
+
constructor(message: string, cause?: unknown);
|
|
22
|
+
}
|
|
23
|
+
export declare class ProactiveTokenRefresher {
|
|
24
|
+
private readonly options;
|
|
25
|
+
private current;
|
|
26
|
+
private obtainedAt;
|
|
27
|
+
private timer;
|
|
28
|
+
private stopped;
|
|
29
|
+
private readonly listeners;
|
|
30
|
+
private readonly clock;
|
|
31
|
+
private readonly logger;
|
|
32
|
+
private readonly fraction;
|
|
33
|
+
private readonly retryInitialMs;
|
|
34
|
+
private readonly retryMaxMs;
|
|
35
|
+
private readonly onFatal;
|
|
36
|
+
private constructor();
|
|
37
|
+
static start(options: ProactiveTokenRefresherOptions): Promise<ProactiveTokenRefresher>;
|
|
38
|
+
token(): string;
|
|
39
|
+
currentToken(): AccessToken;
|
|
40
|
+
subscribe(listener: AccessTokenListener): Promise<() => void>;
|
|
41
|
+
stop(): void;
|
|
42
|
+
private scheduleNext;
|
|
43
|
+
private arm;
|
|
44
|
+
private refresh;
|
|
45
|
+
private fail;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=proactive-token-refresher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proactive-token-refresher.d.ts","sourceRoot":"","sources":["../../src/lib/proactive-token-refresher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,MAAM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