@ekanos/sdk 0.18.0 → 0.20.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/api-report.md +112 -2
- package/dist/components/base-activation-dialog.js +1 -1
- package/dist/components/base-activation-dialog.js.map +1 -1
- package/dist/components/current-return-path.d.ts +16 -1
- package/dist/components/current-return-path.js +18 -1
- package/dist/components/current-return-path.js.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/oauth-activation-form.js +2 -2
- package/dist/components/oauth-activation-form.js.map +1 -1
- package/dist/components/widgets/ai-prompt-chip.js +1 -1
- package/dist/components/widgets/ai-prompt-chip.js.map +1 -1
- package/dist/components/widgets/widget-ask-bar.js +2 -2
- package/dist/components/widgets/widget-ask-bar.js.map +1 -1
- package/dist/components/widgets/widget-state-components.js +1 -1
- package/dist/components/widgets/widget-state-components.js.map +1 -1
- package/dist/components/widgets/widget.js +19 -4
- package/dist/components/widgets/widget.js.map +1 -1
- package/dist/contract/derive-contract.d.ts +14 -0
- package/dist/contract/derive-contract.js +237 -0
- package/dist/contract/derive-contract.js.map +1 -0
- package/dist/contract/index.d.ts +8 -0
- package/dist/contract/index.js +9 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/synthesize-example.d.ts +6 -0
- package/dist/contract/synthesize-example.js +61 -0
- package/dist/contract/synthesize-example.js.map +1 -0
- package/dist/contract/to-json-schema.d.ts +19 -0
- package/dist/contract/to-json-schema.js +300 -0
- package/dist/contract/to-json-schema.js.map +1 -0
- package/dist/contract/types.d.ts +39 -0
- package/dist/contract/types.js +12 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/experience/client.d.ts +55 -0
- package/dist/experience/client.js +125 -0
- package/dist/experience/client.js.map +1 -0
- package/dist/experience/define-experience.d.ts +172 -0
- package/dist/experience/define-experience.js +147 -0
- package/dist/experience/define-experience.js.map +1 -0
- package/dist/experience/index.d.ts +13 -0
- package/dist/experience/index.js +13 -0
- package/dist/experience/index.js.map +1 -0
- package/dist/experience/runtime.d.ts +54 -0
- package/dist/experience/runtime.js +2 -0
- package/dist/experience/runtime.js.map +1 -0
- package/dist/experience/server.d.ts +11 -0
- package/dist/experience/server.js +47 -0
- package/dist/experience/server.js.map +1 -0
- package/dist/experience/types.d.ts +76 -0
- package/dist/experience/types.js +2 -0
- package/dist/experience/types.js.map +1 -0
- package/dist/experience/workflow-template.d.ts +103 -0
- package/dist/experience/workflow-template.js +132 -0
- package/dist/experience/workflow-template.js.map +1 -0
- package/dist/hooks/use-oauth-connection-status.d.ts +7 -217
- package/dist/hooks/use-oauth-connection-status.js +17 -1
- package/dist/hooks/use-oauth-connection-status.js.map +1 -1
- package/dist/types/integration.d.ts +3 -3
- package/dist/types/integration.js.map +1 -1
- package/eslint.design-preset.mjs +3 -2
- package/eslint.design-rules.mjs +285 -3
- package/eslint.experience-preset.mjs +85 -0
- package/package.json +44 -6
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { TEMPLATE_INSTALLATION_ID, type WorkflowTemplate as EngineWorkflowTemplate } from '@ekanos/integration-schema';
|
|
2
|
+
import type { OperationInput, OperationKey, IntegrationName } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A reference to an earlier step's output (`{ ref: 'draft.title' }`), the
|
|
5
|
+
* workflow engine's operand shape. Build one with {@link ref}.
|
|
6
|
+
*/
|
|
7
|
+
export interface WorkflowRef {
|
|
8
|
+
readonly ref: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ref(path: string): WorkflowRef;
|
|
11
|
+
/** Each input field may be literal or a reference to an earlier step's output. */
|
|
12
|
+
export type WithRefs<T> = T extends readonly unknown[] ? T | WorkflowRef : T extends object ? {
|
|
13
|
+
[P in keyof T]: WithRefs<T[P]> | WorkflowRef;
|
|
14
|
+
} : T | WorkflowRef;
|
|
15
|
+
export interface StepOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Step id(s) this step follows. Default: the previous step in `build()`
|
|
18
|
+
* order (the first step follows nothing).
|
|
19
|
+
*/
|
|
20
|
+
after?: string | readonly string[];
|
|
21
|
+
}
|
|
22
|
+
export interface ToolStep {
|
|
23
|
+
readonly type: 'tool';
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly integration: string;
|
|
26
|
+
/** `tool/<name>` or `action/<name>`; effect comes from the pinned contract. */
|
|
27
|
+
readonly op: string;
|
|
28
|
+
readonly args: Record<string, unknown>;
|
|
29
|
+
readonly after?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface AiStep {
|
|
32
|
+
readonly type: 'ai';
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly kind: string;
|
|
35
|
+
readonly instructions: string;
|
|
36
|
+
readonly outputSchemaRef: string;
|
|
37
|
+
readonly after?: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
export interface ApprovalStep {
|
|
40
|
+
readonly type: 'approval';
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly summary: string;
|
|
43
|
+
readonly approverScope: 'account' | 'user';
|
|
44
|
+
readonly after?: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
export type WorkflowStep = ToolStep | AiStep | ApprovalStep;
|
|
47
|
+
/**
|
|
48
|
+
* Step constructors for {@link defineWorkflowTemplate}.
|
|
49
|
+
*
|
|
50
|
+
* `step.tool` is typed from the generated registry: the integration, the operation
|
|
51
|
+
* and its `args` are checked against the pinned contract. Whether a tool step
|
|
52
|
+
* reads or writes is NOT authored; it is read from the contract at build, so a
|
|
53
|
+
* template cannot call a write as if it were a read.
|
|
54
|
+
*/
|
|
55
|
+
export declare const step: {
|
|
56
|
+
tool<S extends IntegrationName, K extends OperationKey<S>>(id: string, integration: S, op: K, args: WithRefs<OperationInput<S, K>>, options?: StepOptions): ToolStep;
|
|
57
|
+
ai(id: string, config: {
|
|
58
|
+
instructions: string;
|
|
59
|
+
outputSchemaRef: string;
|
|
60
|
+
kind?: string;
|
|
61
|
+
}, options?: StepOptions): AiStep;
|
|
62
|
+
approval(id: string, config: {
|
|
63
|
+
summary: string;
|
|
64
|
+
approverScope?: 'account' | 'user';
|
|
65
|
+
}, options?: StepOptions): ApprovalStep;
|
|
66
|
+
};
|
|
67
|
+
export interface WorkflowTemplateInput {
|
|
68
|
+
/** kebab-case, unique within the experience. */
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
/** A 5-field cron expression. Omit for a template that is started by hand. */
|
|
72
|
+
schedule?: string;
|
|
73
|
+
scope?: 'account' | 'user';
|
|
74
|
+
/** Evaluated at `ekanos build`, never at runtime. */
|
|
75
|
+
build: () => readonly WorkflowStep[];
|
|
76
|
+
}
|
|
77
|
+
export interface WorkflowTemplate {
|
|
78
|
+
readonly kind: 'workflow-template';
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly schedule?: string;
|
|
82
|
+
readonly scope: 'account' | 'user';
|
|
83
|
+
readonly build: () => readonly WorkflowStep[];
|
|
84
|
+
}
|
|
85
|
+
export declare function defineWorkflowTemplate(input: WorkflowTemplateInput): WorkflowTemplate;
|
|
86
|
+
/** The serialized workflow the host's engine runs (validated by `WorkflowTemplateSchema`). */
|
|
87
|
+
export type WorkflowDsl = EngineWorkflowTemplate;
|
|
88
|
+
export { TEMPLATE_INSTALLATION_ID };
|
|
89
|
+
export interface SerializeWorkflowOptions {
|
|
90
|
+
/**
|
|
91
|
+
* Reads `read`/`write` for an integration operation from the pinned contract. Return
|
|
92
|
+
* `undefined` when the operation is unknown: serialization then throws, so
|
|
93
|
+
* a template can never name an operation the contract lacks.
|
|
94
|
+
*/
|
|
95
|
+
effectOf: (integration: string, op: string) => 'read' | 'write' | undefined;
|
|
96
|
+
installationId?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Turn a template into the engine's DSL. Pure and deterministic: the same
|
|
100
|
+
* template and contracts always give the same JSON (it is hashed into the
|
|
101
|
+
* manifest digest).
|
|
102
|
+
*/
|
|
103
|
+
export declare function serializeWorkflowTemplate(template: WorkflowTemplate, options: SerializeWorkflowOptions): WorkflowDsl;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { TEMPLATE_INSTALLATION_ID, } from '@ekanos/integration-schema';
|
|
2
|
+
export function ref(path) {
|
|
3
|
+
if (path.trim() === '')
|
|
4
|
+
throw new Error('ref(): path must not be empty.');
|
|
5
|
+
return { ref: path };
|
|
6
|
+
}
|
|
7
|
+
const afterOf = (options) => (options === null || options === void 0 ? void 0 : options.after) === undefined
|
|
8
|
+
? {}
|
|
9
|
+
: {
|
|
10
|
+
after: typeof options.after === 'string'
|
|
11
|
+
? [options.after]
|
|
12
|
+
: [...options.after],
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Step constructors for {@link defineWorkflowTemplate}.
|
|
16
|
+
*
|
|
17
|
+
* `step.tool` is typed from the generated registry: the integration, the operation
|
|
18
|
+
* and its `args` are checked against the pinned contract. Whether a tool step
|
|
19
|
+
* reads or writes is NOT authored; it is read from the contract at build, so a
|
|
20
|
+
* template cannot call a write as if it were a read.
|
|
21
|
+
*/
|
|
22
|
+
export const step = {
|
|
23
|
+
tool(id, integration, op, args, options) {
|
|
24
|
+
return Object.assign({ type: 'tool', id,
|
|
25
|
+
integration,
|
|
26
|
+
op, args: args }, afterOf(options));
|
|
27
|
+
},
|
|
28
|
+
ai(id, config, options) {
|
|
29
|
+
var _a;
|
|
30
|
+
return Object.assign({ type: 'ai', id, kind: (_a = config.kind) !== null && _a !== void 0 ? _a : 'draft', instructions: config.instructions, outputSchemaRef: config.outputSchemaRef }, afterOf(options));
|
|
31
|
+
},
|
|
32
|
+
approval(id, config, options) {
|
|
33
|
+
var _a;
|
|
34
|
+
return Object.assign({ type: 'approval', id, summary: config.summary, approverScope: (_a = config.approverScope) !== null && _a !== void 0 ? _a : 'account' }, afterOf(options));
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const TEMPLATE_ID = /^[a-z][a-z0-9-]*$/;
|
|
38
|
+
const STEP_ID = /^[a-z][a-z0-9_]*$/;
|
|
39
|
+
const RESERVED_STEP_IDS = new Set(['trigger', 'item', 'loop', 'run']);
|
|
40
|
+
export function defineWorkflowTemplate(input) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!TEMPLATE_ID.test(input.id)) {
|
|
43
|
+
throw new Error(`defineWorkflowTemplate: id "${input.id}" must be kebab-case (e.g. "morning-digest").`);
|
|
44
|
+
}
|
|
45
|
+
if (input.name.trim() === '') {
|
|
46
|
+
throw new Error(`defineWorkflowTemplate("${input.id}"): name is required.`);
|
|
47
|
+
}
|
|
48
|
+
if (input.schedule !== undefined &&
|
|
49
|
+
input.schedule.trim().split(/\s+/).length !== 5) {
|
|
50
|
+
throw new Error(`defineWorkflowTemplate("${input.id}"): schedule must be a 5-field cron expression, got "${input.schedule}".`);
|
|
51
|
+
}
|
|
52
|
+
return Object.freeze(Object.assign(Object.assign({ kind: 'workflow-template', id: input.id, name: input.name }, (input.schedule === undefined ? {} : { schedule: input.schedule })), { scope: (_a = input.scope) !== null && _a !== void 0 ? _a : 'account', build: input.build }));
|
|
53
|
+
}
|
|
54
|
+
export { TEMPLATE_INSTALLATION_ID };
|
|
55
|
+
/**
|
|
56
|
+
* Turn a template into the engine's DSL. Pure and deterministic: the same
|
|
57
|
+
* template and contracts always give the same JSON (it is hashed into the
|
|
58
|
+
* manifest digest).
|
|
59
|
+
*/
|
|
60
|
+
export function serializeWorkflowTemplate(template, options) {
|
|
61
|
+
var _a;
|
|
62
|
+
const steps = template.build();
|
|
63
|
+
const installationId = (_a = options.installationId) !== null && _a !== void 0 ? _a : TEMPLATE_INSTALLATION_ID;
|
|
64
|
+
const where = `workflow template "${template.id}"`;
|
|
65
|
+
if (steps.length === 0)
|
|
66
|
+
throw new Error(`${where}: build() returned no steps.`);
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
for (const s of steps) {
|
|
69
|
+
if (!STEP_ID.test(s.id) || RESERVED_STEP_IDS.has(s.id)) {
|
|
70
|
+
throw new Error(`${where}: step id "${s.id}" is invalid or reserved.`);
|
|
71
|
+
}
|
|
72
|
+
if (seen.has(s.id))
|
|
73
|
+
throw new Error(`${where}: step id "${s.id}" is used twice.`);
|
|
74
|
+
seen.add(s.id);
|
|
75
|
+
}
|
|
76
|
+
const edges = [];
|
|
77
|
+
steps.forEach((s, index) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const predecessors = (_a = s.after) !== null && _a !== void 0 ? _a : (index === 0 ? [] : [steps[index - 1].id]);
|
|
80
|
+
for (const from of predecessors) {
|
|
81
|
+
if (!seen.has(from)) {
|
|
82
|
+
throw new Error(`${where}: step "${s.id}" follows unknown step "${from}".`);
|
|
83
|
+
}
|
|
84
|
+
edges.push({ from, to: s.id });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const dslSteps = steps.map((s) => {
|
|
88
|
+
switch (s.type) {
|
|
89
|
+
case 'tool': {
|
|
90
|
+
const effect = options.effectOf(s.integration, s.op);
|
|
91
|
+
if (effect === undefined) {
|
|
92
|
+
throw new Error(`${where}: step "${s.id}" calls ${s.integration} ${s.op}, which the pinned contract does not declare.`);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
id: s.id,
|
|
96
|
+
type: 'fusion_tool',
|
|
97
|
+
tool: s.op,
|
|
98
|
+
installationId,
|
|
99
|
+
slot: s.integration,
|
|
100
|
+
args: s.args,
|
|
101
|
+
effect,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
case 'ai':
|
|
105
|
+
return {
|
|
106
|
+
id: s.id,
|
|
107
|
+
type: 'ai_step',
|
|
108
|
+
kind: s.kind,
|
|
109
|
+
instructions: s.instructions,
|
|
110
|
+
outputSchemaRef: s.outputSchemaRef,
|
|
111
|
+
};
|
|
112
|
+
case 'approval':
|
|
113
|
+
return {
|
|
114
|
+
id: s.id,
|
|
115
|
+
type: 'approval_gate',
|
|
116
|
+
summaryTemplate: s.summary,
|
|
117
|
+
approverScope: s.approverScope,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
version: '1',
|
|
123
|
+
name: template.name,
|
|
124
|
+
scope: template.scope,
|
|
125
|
+
trigger: template.schedule === undefined
|
|
126
|
+
? { type: 'manual' }
|
|
127
|
+
: { type: 'schedule', cron: template.schedule },
|
|
128
|
+
steps: dslSteps,
|
|
129
|
+
edges,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=workflow-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-template.js","sourceRoot":"","sources":["../../src/experience/workflow-template.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AAYpC,MAAM,UAAU,GAAG,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAE1E,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC;AA8CD,MAAM,OAAO,GAAG,CAAC,OAAgC,EAAE,EAAE,CACnD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,MAAK,SAAS;IAC1B,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC;QACE,KAAK,EACH,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC/B,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;YACjB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;KACzB,CAAC;AAER;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,IAAI,CACF,EAAU,EACV,WAAc,EACd,EAAK,EACL,IAAoC,EACpC,OAAqB;QAErB,uBACE,IAAI,EAAE,MAAM,EACZ,EAAE;YACF,WAAW;YACX,EAAE,EACF,IAAI,EAA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,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,EAAE,+CAA+C,CACvG,CAAC;gBACJ,CAAC;gBAED,OAAO;oBACL,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,CAAC,CAAC,EAAE;oBACV,cAAc;oBACd,IAAI,EAAE,CAAC,CAAC,WAAW;oBACnB,IAAI,EAAE,CAAC,CAAC,IAGC;oBACT,MAAM;iBACP,CAAC;YACJ,CAAC;YACD,KAAK,IAAI;gBACP,OAAO;oBACL,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,YAAY,EAAE,CAAC,CAAC,YAAY;oBAC5B,eAAe,EAAE,CAAC,CAAC,eAAe;iBACnC,CAAC;YACJ,KAAK,UAAU;gBACb,OAAO;oBACL,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,IAAI,EAAE,eAAe;oBACrB,eAAe,EAAE,CAAC,CAAC,OAAO;oBAC1B,aAAa,EAAE,CAAC,CAAC,aAAa;iBAC/B,CAAC;QACN,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,GAAG;QACZ,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,OAAO,EACL,QAAQ,CAAC,QAAQ,KAAK,SAAS;YAC7B,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE;YACpB,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE;QACnD,KAAK,EAAE,QAAQ;QACf,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import {\n TEMPLATE_INSTALLATION_ID,\n type WorkflowTemplate as EngineWorkflowTemplate,\n} from '@ekanos/integration-schema';\n\nimport type { OperationInput, OperationKey, IntegrationName } from './types';\n\n/**\n * A reference to an earlier step's output (`{ ref: 'draft.title' }`), the\n * workflow engine's operand shape. Build one with {@link ref}.\n */\nexport interface WorkflowRef {\n readonly ref: string;\n}\n\nexport function ref(path: string): WorkflowRef {\n if (path.trim() === '') throw new Error('ref(): path must not be empty.');\n\n return { ref: path };\n}\n\n/** Each input field may be literal or a reference to an earlier step's output. */\nexport type WithRefs<T> = T extends readonly unknown[]\n ? T | WorkflowRef\n : T extends object\n ? { [P in keyof T]: WithRefs<T[P]> | WorkflowRef }\n : T | WorkflowRef;\n\nexport interface StepOptions {\n /**\n * Step id(s) this step follows. Default: the previous step in `build()`\n * order (the first step follows nothing).\n */\n after?: string | readonly string[];\n}\n\nexport interface ToolStep {\n readonly type: 'tool';\n readonly id: string;\n readonly integration: string;\n /** `tool/<name>` or `action/<name>`; effect comes from the pinned contract. */\n readonly op: string;\n readonly args: Record<string, unknown>;\n readonly after?: readonly string[];\n}\n\nexport interface AiStep {\n readonly type: 'ai';\n readonly id: string;\n readonly kind: string;\n readonly instructions: string;\n readonly outputSchemaRef: string;\n readonly after?: readonly string[];\n}\n\nexport interface ApprovalStep {\n readonly type: 'approval';\n readonly id: string;\n readonly summary: string;\n readonly approverScope: 'account' | 'user';\n readonly after?: readonly string[];\n}\n\nexport type WorkflowStep = ToolStep | AiStep | ApprovalStep;\n\nconst afterOf = (options: StepOptions | undefined) =>\n options?.after === undefined\n ? {}\n : {\n after:\n typeof options.after === 'string'\n ? [options.after]\n : [...options.after],\n };\n\n/**\n * Step constructors for {@link defineWorkflowTemplate}.\n *\n * `step.tool` is typed from the generated registry: the integration, the operation\n * and its `args` are checked against the pinned contract. Whether a tool step\n * reads or writes is NOT authored; it is read from the contract at build, so a\n * template cannot call a write as if it were a read.\n */\nexport const step = {\n tool<S extends IntegrationName, K extends OperationKey<S>>(\n id: string,\n integration: S,\n op: K,\n args: WithRefs<OperationInput<S, K>>,\n options?: StepOptions,\n ): ToolStep {\n return {\n type: 'tool',\n id,\n integration,\n op,\n args: args as Record<string, unknown>,\n ...afterOf(options),\n };\n },\n ai(\n id: string,\n config: { instructions: string; outputSchemaRef: string; kind?: string },\n options?: StepOptions,\n ): AiStep {\n return {\n type: 'ai',\n id,\n kind: config.kind ?? 'draft',\n instructions: config.instructions,\n outputSchemaRef: config.outputSchemaRef,\n ...afterOf(options),\n };\n },\n approval(\n id: string,\n config: { summary: string; approverScope?: 'account' | 'user' },\n options?: StepOptions,\n ): ApprovalStep {\n return {\n type: 'approval',\n id,\n summary: config.summary,\n approverScope: config.approverScope ?? 'account',\n ...afterOf(options),\n };\n },\n};\n\nconst TEMPLATE_ID = /^[a-z][a-z0-9-]*$/;\nconst STEP_ID = /^[a-z][a-z0-9_]*$/;\nconst RESERVED_STEP_IDS = new Set(['trigger', 'item', 'loop', 'run']);\n\nexport interface WorkflowTemplateInput {\n /** kebab-case, unique within the experience. */\n id: string;\n name: string;\n /** A 5-field cron expression. Omit for a template that is started by hand. */\n schedule?: string;\n scope?: 'account' | 'user';\n /** Evaluated at `ekanos build`, never at runtime. */\n build: () => readonly WorkflowStep[];\n}\n\nexport interface WorkflowTemplate {\n readonly kind: 'workflow-template';\n readonly id: string;\n readonly name: string;\n readonly schedule?: string;\n readonly scope: 'account' | 'user';\n readonly build: () => readonly WorkflowStep[];\n}\n\nexport function defineWorkflowTemplate(\n input: WorkflowTemplateInput,\n): WorkflowTemplate {\n if (!TEMPLATE_ID.test(input.id)) {\n throw new Error(\n `defineWorkflowTemplate: id \"${input.id}\" must be kebab-case (e.g. \"morning-digest\").`,\n );\n }\n if (input.name.trim() === '') {\n throw new Error(`defineWorkflowTemplate(\"${input.id}\"): name is required.`);\n }\n if (\n input.schedule !== undefined &&\n input.schedule.trim().split(/\\s+/).length !== 5\n ) {\n throw new Error(\n `defineWorkflowTemplate(\"${input.id}\"): schedule must be a 5-field cron expression, got \"${input.schedule}\".`,\n );\n }\n\n return Object.freeze({\n kind: 'workflow-template' as const,\n id: input.id,\n name: input.name,\n ...(input.schedule === undefined ? {} : { schedule: input.schedule }),\n scope: input.scope ?? 'account',\n build: input.build,\n });\n}\n\n/** The serialized workflow the host's engine runs (validated by `WorkflowTemplateSchema`). */\nexport type WorkflowDsl = EngineWorkflowTemplate;\n\nexport { TEMPLATE_INSTALLATION_ID };\n\nexport interface SerializeWorkflowOptions {\n /**\n * Reads `read`/`write` for an integration operation from the pinned contract. Return\n * `undefined` when the operation is unknown: serialization then throws, so\n * a template can never name an operation the contract lacks.\n */\n effectOf: (integration: string, op: string) => 'read' | 'write' | undefined;\n installationId?: string;\n}\n\n/**\n * Turn a template into the engine's DSL. Pure and deterministic: the same\n * template and contracts always give the same JSON (it is hashed into the\n * manifest digest).\n */\nexport function serializeWorkflowTemplate(\n template: WorkflowTemplate,\n options: SerializeWorkflowOptions,\n): WorkflowDsl {\n const steps = template.build();\n const installationId = options.installationId ?? TEMPLATE_INSTALLATION_ID;\n const where = `workflow template \"${template.id}\"`;\n\n if (steps.length === 0)\n throw new Error(`${where}: build() returned no steps.`);\n\n const seen = new Set<string>();\n for (const s of steps) {\n if (!STEP_ID.test(s.id) || RESERVED_STEP_IDS.has(s.id)) {\n throw new Error(`${where}: step id \"${s.id}\" is invalid or reserved.`);\n }\n if (seen.has(s.id))\n throw new Error(`${where}: step id \"${s.id}\" is used twice.`);\n seen.add(s.id);\n }\n\n const edges: WorkflowDsl['edges'] = [];\n steps.forEach((s, index) => {\n const predecessors = s.after ?? (index === 0 ? [] : [steps[index - 1]!.id]);\n for (const from of predecessors) {\n if (!seen.has(from)) {\n throw new Error(\n `${where}: step \"${s.id}\" follows unknown step \"${from}\".`,\n );\n }\n edges.push({ from, to: s.id });\n }\n });\n\n const dslSteps = steps.map((s): WorkflowDsl['steps'][number] => {\n switch (s.type) {\n case 'tool': {\n const effect = options.effectOf(s.integration, s.op);\n if (effect === undefined) {\n throw new Error(\n `${where}: step \"${s.id}\" calls ${s.integration} ${s.op}, which the pinned contract does not declare.`,\n );\n }\n\n return {\n id: s.id,\n type: 'fusion_tool',\n tool: s.op,\n installationId,\n slot: s.integration,\n args: s.args as Extract<\n WorkflowDsl['steps'][number],\n { type: 'fusion_tool' }\n >['args'],\n effect,\n };\n }\n case 'ai':\n return {\n id: s.id,\n type: 'ai_step',\n kind: s.kind,\n instructions: s.instructions,\n outputSchemaRef: s.outputSchemaRef,\n };\n case 'approval':\n return {\n id: s.id,\n type: 'approval_gate',\n summaryTemplate: s.summary,\n approverScope: s.approverScope,\n };\n }\n });\n\n return {\n version: '1',\n name: template.name,\n scope: template.scope,\n trigger:\n template.schedule === undefined\n ? { type: 'manual' }\n : { type: 'schedule', cron: template.schedule },\n steps: dslSteps,\n edges,\n };\n}\n"]}
|
|
@@ -40,137 +40,6 @@ export interface UseOAuthConnectionStatusOptions {
|
|
|
40
40
|
* connected without a manual refresh.
|
|
41
41
|
*/
|
|
42
42
|
export declare function useOAuthConnectionStatus(accountId: string, options: UseOAuthConnectionStatusOptions): {
|
|
43
|
-
dataUpdatedAt: number;
|
|
44
|
-
errorUpdatedAt: number;
|
|
45
|
-
failureCount: number;
|
|
46
|
-
failureReason: Error | null;
|
|
47
|
-
errorUpdateCount: number;
|
|
48
|
-
isFetched: boolean;
|
|
49
|
-
isFetchedAfterMount: boolean;
|
|
50
|
-
isFetching: boolean;
|
|
51
|
-
isInitialLoading: boolean;
|
|
52
|
-
isPaused: boolean;
|
|
53
|
-
isRefetching: boolean;
|
|
54
|
-
isStale: boolean;
|
|
55
|
-
isEnabled: boolean;
|
|
56
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
|
|
57
|
-
isConnected: boolean;
|
|
58
|
-
error: string | undefined;
|
|
59
|
-
obtainedAt?: undefined;
|
|
60
|
-
} | {
|
|
61
|
-
error?: undefined;
|
|
62
|
-
isConnected: boolean;
|
|
63
|
-
obtainedAt: string | null | undefined;
|
|
64
|
-
}, Error>>;
|
|
65
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
66
|
-
data: undefined;
|
|
67
|
-
error: Error;
|
|
68
|
-
isError: true;
|
|
69
|
-
isPending: false;
|
|
70
|
-
isLoading: false;
|
|
71
|
-
isLoadingError: true;
|
|
72
|
-
isRefetchError: false;
|
|
73
|
-
isSuccess: false;
|
|
74
|
-
isPlaceholderData: false;
|
|
75
|
-
status: 'error';
|
|
76
|
-
oauthJustCompleted: boolean;
|
|
77
|
-
oauthError: string | null;
|
|
78
|
-
} | {
|
|
79
|
-
dataUpdatedAt: number;
|
|
80
|
-
errorUpdatedAt: number;
|
|
81
|
-
failureCount: number;
|
|
82
|
-
failureReason: Error | null;
|
|
83
|
-
errorUpdateCount: number;
|
|
84
|
-
isFetched: boolean;
|
|
85
|
-
isFetchedAfterMount: boolean;
|
|
86
|
-
isFetching: boolean;
|
|
87
|
-
isInitialLoading: boolean;
|
|
88
|
-
isPaused: boolean;
|
|
89
|
-
isRefetching: boolean;
|
|
90
|
-
isStale: boolean;
|
|
91
|
-
isEnabled: boolean;
|
|
92
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
|
|
93
|
-
isConnected: boolean;
|
|
94
|
-
error: string | undefined;
|
|
95
|
-
obtainedAt?: undefined;
|
|
96
|
-
} | {
|
|
97
|
-
error?: undefined;
|
|
98
|
-
isConnected: boolean;
|
|
99
|
-
obtainedAt: string | null | undefined;
|
|
100
|
-
}, Error>>;
|
|
101
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
102
|
-
data: undefined;
|
|
103
|
-
error: null;
|
|
104
|
-
isError: false;
|
|
105
|
-
isPending: true;
|
|
106
|
-
isLoading: true;
|
|
107
|
-
isLoadingError: false;
|
|
108
|
-
isRefetchError: false;
|
|
109
|
-
isSuccess: false;
|
|
110
|
-
isPlaceholderData: false;
|
|
111
|
-
status: 'pending';
|
|
112
|
-
oauthJustCompleted: boolean;
|
|
113
|
-
oauthError: string | null;
|
|
114
|
-
} | {
|
|
115
|
-
dataUpdatedAt: number;
|
|
116
|
-
errorUpdatedAt: number;
|
|
117
|
-
failureCount: number;
|
|
118
|
-
failureReason: Error | null;
|
|
119
|
-
errorUpdateCount: number;
|
|
120
|
-
isFetched: boolean;
|
|
121
|
-
isFetchedAfterMount: boolean;
|
|
122
|
-
isFetching: boolean;
|
|
123
|
-
isLoading: boolean;
|
|
124
|
-
isInitialLoading: boolean;
|
|
125
|
-
isPaused: boolean;
|
|
126
|
-
isRefetching: boolean;
|
|
127
|
-
isStale: boolean;
|
|
128
|
-
isEnabled: boolean;
|
|
129
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
|
|
130
|
-
isConnected: boolean;
|
|
131
|
-
error: string | undefined;
|
|
132
|
-
obtainedAt?: undefined;
|
|
133
|
-
} | {
|
|
134
|
-
error?: undefined;
|
|
135
|
-
isConnected: boolean;
|
|
136
|
-
obtainedAt: string | null | undefined;
|
|
137
|
-
}, Error>>;
|
|
138
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
139
|
-
data: undefined;
|
|
140
|
-
error: null;
|
|
141
|
-
isError: false;
|
|
142
|
-
isPending: true;
|
|
143
|
-
isLoadingError: false;
|
|
144
|
-
isRefetchError: false;
|
|
145
|
-
isSuccess: false;
|
|
146
|
-
isPlaceholderData: false;
|
|
147
|
-
status: 'pending';
|
|
148
|
-
oauthJustCompleted: boolean;
|
|
149
|
-
oauthError: string | null;
|
|
150
|
-
} | {
|
|
151
|
-
dataUpdatedAt: number;
|
|
152
|
-
errorUpdatedAt: number;
|
|
153
|
-
failureCount: number;
|
|
154
|
-
failureReason: Error | null;
|
|
155
|
-
errorUpdateCount: number;
|
|
156
|
-
isFetched: boolean;
|
|
157
|
-
isFetchedAfterMount: boolean;
|
|
158
|
-
isFetching: boolean;
|
|
159
|
-
isInitialLoading: boolean;
|
|
160
|
-
isPaused: boolean;
|
|
161
|
-
isRefetching: boolean;
|
|
162
|
-
isStale: boolean;
|
|
163
|
-
isEnabled: boolean;
|
|
164
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
|
|
165
|
-
isConnected: boolean;
|
|
166
|
-
error: string | undefined;
|
|
167
|
-
obtainedAt?: undefined;
|
|
168
|
-
} | {
|
|
169
|
-
error?: undefined;
|
|
170
|
-
isConnected: boolean;
|
|
171
|
-
obtainedAt: string | null | undefined;
|
|
172
|
-
}, Error>>;
|
|
173
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
174
43
|
data: {
|
|
175
44
|
isConnected: boolean;
|
|
176
45
|
error: string | undefined;
|
|
@@ -179,76 +48,16 @@ export declare function useOAuthConnectionStatus(accountId: string, options: Use
|
|
|
179
48
|
error?: undefined;
|
|
180
49
|
isConnected: boolean;
|
|
181
50
|
obtainedAt: string | null | undefined;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
isPending:
|
|
186
|
-
isLoading:
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
isSuccess: true;
|
|
190
|
-
isPlaceholderData: true;
|
|
191
|
-
status: 'success';
|
|
192
|
-
oauthJustCompleted: boolean;
|
|
193
|
-
oauthError: string | null;
|
|
194
|
-
} | {
|
|
195
|
-
dataUpdatedAt: number;
|
|
196
|
-
errorUpdatedAt: number;
|
|
197
|
-
failureCount: number;
|
|
198
|
-
failureReason: Error | null;
|
|
199
|
-
errorUpdateCount: number;
|
|
200
|
-
isFetched: boolean;
|
|
201
|
-
isFetchedAfterMount: boolean;
|
|
51
|
+
} | undefined;
|
|
52
|
+
error: Error | null;
|
|
53
|
+
status: "error" | "pending" | "success";
|
|
54
|
+
isPending: boolean;
|
|
55
|
+
isLoading: boolean;
|
|
56
|
+
isError: boolean;
|
|
57
|
+
isSuccess: boolean;
|
|
202
58
|
isFetching: boolean;
|
|
203
|
-
isInitialLoading: boolean;
|
|
204
|
-
isPaused: boolean;
|
|
205
59
|
isRefetching: boolean;
|
|
206
|
-
isStale: boolean;
|
|
207
|
-
isEnabled: boolean;
|
|
208
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
|
|
209
|
-
isConnected: boolean;
|
|
210
|
-
error: string | undefined;
|
|
211
|
-
obtainedAt?: undefined;
|
|
212
|
-
} | {
|
|
213
|
-
error?: undefined;
|
|
214
|
-
isConnected: boolean;
|
|
215
|
-
obtainedAt: string | null | undefined;
|
|
216
|
-
}, Error>>;
|
|
217
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
218
|
-
data: {
|
|
219
|
-
isConnected: boolean;
|
|
220
|
-
error: string | undefined;
|
|
221
|
-
obtainedAt?: undefined;
|
|
222
|
-
} | {
|
|
223
|
-
error?: undefined;
|
|
224
|
-
isConnected: boolean;
|
|
225
|
-
obtainedAt: string | null | undefined;
|
|
226
|
-
};
|
|
227
|
-
error: Error;
|
|
228
|
-
isError: true;
|
|
229
|
-
isPending: false;
|
|
230
|
-
isLoading: false;
|
|
231
|
-
isLoadingError: false;
|
|
232
|
-
isRefetchError: true;
|
|
233
|
-
isSuccess: false;
|
|
234
|
-
isPlaceholderData: false;
|
|
235
|
-
status: 'error';
|
|
236
|
-
oauthJustCompleted: boolean;
|
|
237
|
-
oauthError: string | null;
|
|
238
|
-
} | {
|
|
239
60
|
dataUpdatedAt: number;
|
|
240
|
-
errorUpdatedAt: number;
|
|
241
|
-
failureCount: number;
|
|
242
|
-
failureReason: Error | null;
|
|
243
|
-
errorUpdateCount: number;
|
|
244
|
-
isFetched: boolean;
|
|
245
|
-
isFetchedAfterMount: boolean;
|
|
246
|
-
isFetching: boolean;
|
|
247
|
-
isInitialLoading: boolean;
|
|
248
|
-
isPaused: boolean;
|
|
249
|
-
isRefetching: boolean;
|
|
250
|
-
isStale: boolean;
|
|
251
|
-
isEnabled: boolean;
|
|
252
61
|
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
|
|
253
62
|
isConnected: boolean;
|
|
254
63
|
error: string | undefined;
|
|
@@ -258,25 +67,6 @@ export declare function useOAuthConnectionStatus(accountId: string, options: Use
|
|
|
258
67
|
isConnected: boolean;
|
|
259
68
|
obtainedAt: string | null | undefined;
|
|
260
69
|
}, Error>>;
|
|
261
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
262
|
-
data: {
|
|
263
|
-
isConnected: boolean;
|
|
264
|
-
error: string | undefined;
|
|
265
|
-
obtainedAt?: undefined;
|
|
266
|
-
} | {
|
|
267
|
-
error?: undefined;
|
|
268
|
-
isConnected: boolean;
|
|
269
|
-
obtainedAt: string | null | undefined;
|
|
270
|
-
};
|
|
271
|
-
error: null;
|
|
272
|
-
isError: false;
|
|
273
|
-
isPending: false;
|
|
274
|
-
isLoading: false;
|
|
275
|
-
isLoadingError: false;
|
|
276
|
-
isRefetchError: false;
|
|
277
|
-
isSuccess: true;
|
|
278
|
-
isPlaceholderData: false;
|
|
279
|
-
status: 'success';
|
|
280
70
|
oauthJustCompleted: boolean;
|
|
281
71
|
oauthError: string | null;
|
|
282
72
|
};
|
|
@@ -75,7 +75,23 @@ export function useOAuthConnectionStatus(accountId, options) {
|
|
|
75
75
|
errorParamName,
|
|
76
76
|
queryClient,
|
|
77
77
|
]);
|
|
78
|
-
|
|
78
|
+
// Named, not spread: spreading a query result reads every field, so
|
|
79
|
+
// the component re-renders on all of them (TanStack render optimizations).
|
|
80
|
+
return {
|
|
81
|
+
data: query.data,
|
|
82
|
+
error: query.error,
|
|
83
|
+
status: query.status,
|
|
84
|
+
isPending: query.isPending,
|
|
85
|
+
isLoading: query.isLoading,
|
|
86
|
+
isError: query.isError,
|
|
87
|
+
isSuccess: query.isSuccess,
|
|
88
|
+
isFetching: query.isFetching,
|
|
89
|
+
isRefetching: query.isRefetching,
|
|
90
|
+
dataUpdatedAt: query.dataUpdatedAt,
|
|
91
|
+
refetch: query.refetch,
|
|
92
|
+
oauthJustCompleted,
|
|
93
|
+
oauthError,
|
|
94
|
+
};
|
|
79
95
|
}
|
|
80
96
|
/** Pure: the gate options a slug implies. Exported for tests and for widgets that need the key. */
|
|
81
97
|
export function oauthWidgetGateOptionsFor(slug) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-oauth-connection-status.js","sourceRoot":"","sources":["../../src/hooks/use-oauth-connection-status.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAuC/D;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAiB,EACjB,OAAwC;IAExC,MAAM,EACJ,aAAa,EACb,eAAe,EACf,OAAO,GAAG,IAAI,EACd,UAAU,GACX,GAAG,OAAO,CAAC;IACZ,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,yEAAyE;IACzE,0EAA0E;IAC1E,MAAM,CAAC,kBAAkB,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE;QACzC,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,KAAK,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,MAAM,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAgB,GAAG,EAAE;QAChD,IAAI,CAAC,UAAU,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC9D,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CA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AC;IACrD,MAAM,eAAe,GAAG,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC;IACjD,MAAM,WAAW,GAAG,CAAA,MAAA,KAAK,CAAC,IAAI,0CAAE,WAAW,MAAK,IAAI,CAAC;IACrD,MAAM,WAAW,GAAG,OAAO,IAAI,WAAW,CAAC;IAC3C,0EAA0E;IAC1E,0EAA0E;IAC1E,MAAM,YAAY,GAChB,OAAO,IAAI,CAAC,iBAAiB,IAAI,CAAC,eAAe,IAAI,CAAC,WAAW,CAAC;IAEpE,OAAO;QACL,OAAO;QACP,WAAW;QACX,iBAAiB;QACjB,eAAe;QACf,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nimport { useQuery, useQueryClient } from '@tanstack/react-query';\n\nimport { createPartnerConnectionCheck } from './partner-oauth';\n\n/**\n * Result shape of an integration's check-connection server action\n * (the standard server-action envelope).\n */\nexport interface ConnectionCheckResult {\n success: boolean;\n data?: { obtainedAt?: string | null } | null;\n error?: string;\n}\n\nexport type ConnectionCheckAction = (input: {\n accountId: string;\n}) => Promise<ConnectionCheckResult>;\n\n/**\n * Optional OAuth failure query param an integration's connect route may\n * append on redirect (e.g. dropbox_error=credentials_not_configured).\n */\nexport interface OAuthErrorParam {\n name: string;\n /** Map the raw param value to a user-facing message; return null to ignore. */\n toMessage: (value: string) => string | null;\n}\n\nexport interface UseOAuthConnectionStatusOptions {\n /**\n * Cache key segment, by convention `<slug>-connection`. The full query key\n * is ['integration-data', accountId, connectionKey] so all widgets and the\n * activation form share one deduped request per dashboard load.\n */\n connectionKey: string;\n checkConnection: ConnectionCheckAction;\n /** Gate the query (e.g. on integration-active state). Defaults to true. */\n enabled?: boolean;\n errorParam?: OAuthErrorParam;\n}\n\n/**\n * Shared OAuth connection-status hook. Detects the `oauth_success=true`\n * return from an integration's connect route, strips the transient params\n * from the URL, and invalidates the cached status so dependent UI flips to\n * connected without a manual refresh.\n */\nexport function useOAuthConnectionStatus(\n accountId: string,\n options: UseOAuthConnectionStatusOptions,\n) {\n const {\n connectionKey,\n checkConnection,\n enabled = true,\n errorParam,\n } = options;\n const queryClient = useQueryClient();\n\n // Read the OAuth return params synchronously on mount (not in an effect)\n // so the first render already knows whether we just came back from OAuth.\n const [oauthJustCompleted] = useState(() => {\n if (typeof window === 'undefined') return false;\n const params = new URLSearchParams(window.location.search);\n return params.get('oauth_success') === 'true';\n });\n\n const [oauthError] = useState<string | null>(() => {\n if (!errorParam || typeof window === 'undefined') return null;\n const value = new URLSearchParams(window.location.search).get(\n errorParam.name,\n );\n return value ? errorParam.toMessage(value) : null;\n });\n\n const query = useQuery({\n queryKey: ['integration-data', accountId, connectionKey],\n queryFn: async () => {\n const result = await checkConnection({ accountId });\n\n if (!result.success) {\n return { isConnected: false, error: result.error };\n }\n\n return {\n isConnected: true,\n obtainedAt: result.data?.obtainedAt,\n };\n },\n enabled: enabled && !!accountId,\n staleTime: 5 * 60 * 1000,\n refetchOnWindowFocus: false,\n });\n\n const errorParamName = errorParam?.name;\n\n const returnedWithError = oauthError !== null;\n\n // Justified useEffect: after the OAuth redirect lands back on this page —\n // with `?oauth_success=true` OR with the integration's error param — we\n // must (1) strip the transient query params from the URL, so a reload does\n // not re-announce a stale success or re-show a stale error, and (2) on\n // success invalidate the cached connection status so widgets flip to\n // connected without a manual refresh. Both are post-render side effects\n // on external systems (history API + query cache), not derivable during\n // render. The error itself stays in state for this render, so the alert\n // still shows once.\n useEffect(() => {\n if (!oauthJustCompleted && !returnedWithError) return;\n\n const url = new URL(window.location.href);\n url.searchParams.delete('oauth_success');\n\n if (errorParamName) {\n url.searchParams.delete(errorParamName);\n }\n\n window.history.replaceState({}, '', url.pathname + url.search);\n\n if (oauthJustCompleted) {\n queryClient.invalidateQueries({\n queryKey: ['integration-data', accountId, connectionKey],\n });\n }\n }, [\n oauthJustCompleted,\n returnedWithError,\n accountId,\n connectionKey,\n errorParamName,\n queryClient,\n ]);\n\n return { ...query, oauthJustCompleted, oauthError };\n}\n\n/**\n * Resolves the gating booleans every OAuth-backed dashboard widget needs:\n *\n * - `enabled` — the integration is active and an account id is present.\n * - `isConnected` — a live OAuth connection exists (access token).\n * - `dataEnabled` — safe to fire the widget's data query (active + connected).\n * - `connectionPending` — still resolving the connection status.\n * - `connectionError` — the connection check itself failed (network/5xx).\n * Distinct from `notConnected`: a transient failure should surface as an\n * error, not as a misleading \"connect X\" prompt.\n * - `notConnected` — activated, resolved without error, but no OAuth\n * connection. The widget should render its \"connect X\" inactive state.\n *\n * The underlying connection check shares one query key across all widgets,\n * so react-query dedupes it to a single request per dashboard load.\n */\nexport type OAuthWidgetGateOptions =\n | (Pick<\n UseOAuthConnectionStatusOptions,\n 'connectionKey' | 'checkConnection'\n > & {\n slug?: never;\n })\n /**\n * The hosted-transport shorthand: for an integration whose connection is\n * checked at `GET /api/integrations/<slug>/oauth/status`, the slug is the\n * only fact the gate needs — the key is `<slug>-connection` by convention\n * and the check is `createPartnerConnectionCheck(slug)`.\n */\n | { slug: string; connectionKey?: never; checkConnection?: never };\n\n/** Pure: the gate options a slug implies. Exported for tests and for widgets that need the key. */\nexport function oauthWidgetGateOptionsFor(\n slug: string,\n): Pick<UseOAuthConnectionStatusOptions, 'connectionKey' | 'checkConnection'> {\n return {\n connectionKey: `${slug}-connection`,\n checkConnection: createPartnerConnectionCheck(slug),\n };\n}\n\nexport function useOAuthWidgetGate(\n accountId: string | undefined,\n integrationActive: boolean,\n options: OAuthWidgetGateOptions,\n) {\n const enabled = integrationActive && !!accountId;\n const resolved =\n options.slug !== undefined\n ? oauthWidgetGateOptionsFor(options.slug)\n : options;\n const query = useOAuthConnectionStatus(accountId ?? '', {\n ...resolved,\n enabled,\n });\n\n const connectionPending = enabled && query.isPending;\n const connectionError = enabled && query.isError;\n const isConnected = query.data?.isConnected === true;\n const dataEnabled = enabled && isConnected;\n // Only treat as \"not connected\" when the check resolved successfully with\n // no token — a query error is an error state, not a disconnected account.\n const notConnected =\n enabled && !connectionPending && !connectionError && !isConnected;\n\n return {\n enabled,\n isConnected,\n connectionPending,\n connectionError,\n dataEnabled,\n notConnected,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-oauth-connection-status.js","sourceRoot":"","sources":["../../src/hooks/use-oauth-connection-status.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAuC/D;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAiB,EACjB,OAAwC;IAExC,MAAM,EACJ,aAAa,EACb,eAAe,EACf,OAAO,GAAG,IAAI,EACd,UAAU,GACX,GAAG,OAAO,CAAC;IACZ,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,yEAAyE;IACzE,0EAA0E;IAC1E,MAAM,CAAC,kBAAkB,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE;QACzC,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,KAAK,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,MAAM,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAgB,GAAG,EAAE;QAChD,IAAI,CAAC,UAAU,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC9D,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAC3D,UAAU,CAAC,IAAI,CAChB,CAAC;QACF,OAAO,KAAK,CAAC,CAAC,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IAAI,CAAC,CAAC,SAAS,CAAC;IACjD,MAAM,QAAQ,GACZ,OAAO,CAAC,IAAI,KAAK,SAAS;QACxB,CAAC,CAAC,yBAAyB,CAAC,OAAO,CAAC,IAAI,CAAC;QACzC,CAAC,CAAC,OAAO,CAAC;IACd,MAAM,KAAK,GAAG,wBAAwB,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,kCACjD,QAAQ,KACX,OAAO,IACP,CAAC;IAEH,MAAM,iBAAiB,GAAG,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC;IACrD,MAAM,eAAe,GAAG,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC;IACjD,MAAM,WAAW,GAAG,CAAA,MAAA,KAAK,CAAC,IAAI,0CAAE,WAAW,MAAK,IAAI,CAAC;IACrD,MAAM,WAAW,GAAG,OAAO,IAAI,WAAW,CAAC;IAC3C,0EAA0E;IAC1E,0EAA0E;IAC1E,MAAM,YAAY,GAChB,OAAO,IAAI,CAAC,iBAAiB,IAAI,CAAC,eAAe,IAAI,CAAC,WAAW,CAAC;IAEpE,OAAO;QACL,OAAO;QACP,WAAW;QACX,iBAAiB;QACjB,eAAe;QACf,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nimport { useQuery, useQueryClient } from '@tanstack/react-query';\n\nimport { createPartnerConnectionCheck } from './partner-oauth';\n\n/**\n * Result shape of an integration's check-connection server action\n * (the standard server-action envelope).\n */\nexport interface ConnectionCheckResult {\n success: boolean;\n data?: { obtainedAt?: string | null } | null;\n error?: string;\n}\n\nexport type ConnectionCheckAction = (input: {\n accountId: string;\n}) => Promise<ConnectionCheckResult>;\n\n/**\n * Optional OAuth failure query param an integration's connect route may\n * append on redirect (e.g. dropbox_error=credentials_not_configured).\n */\nexport interface OAuthErrorParam {\n name: string;\n /** Map the raw param value to a user-facing message; return null to ignore. */\n toMessage: (value: string) => string | null;\n}\n\nexport interface UseOAuthConnectionStatusOptions {\n /**\n * Cache key segment, by convention `<slug>-connection`. The full query key\n * is ['integration-data', accountId, connectionKey] so all widgets and the\n * activation form share one deduped request per dashboard load.\n */\n connectionKey: string;\n checkConnection: ConnectionCheckAction;\n /** Gate the query (e.g. on integration-active state). Defaults to true. */\n enabled?: boolean;\n errorParam?: OAuthErrorParam;\n}\n\n/**\n * Shared OAuth connection-status hook. Detects the `oauth_success=true`\n * return from an integration's connect route, strips the transient params\n * from the URL, and invalidates the cached status so dependent UI flips to\n * connected without a manual refresh.\n */\nexport function useOAuthConnectionStatus(\n accountId: string,\n options: UseOAuthConnectionStatusOptions,\n) {\n const {\n connectionKey,\n checkConnection,\n enabled = true,\n errorParam,\n } = options;\n const queryClient = useQueryClient();\n\n // Read the OAuth return params synchronously on mount (not in an effect)\n // so the first render already knows whether we just came back from OAuth.\n const [oauthJustCompleted] = useState(() => {\n if (typeof window === 'undefined') return false;\n const params = new URLSearchParams(window.location.search);\n return params.get('oauth_success') === 'true';\n });\n\n const [oauthError] = useState<string | null>(() => {\n if (!errorParam || typeof window === 'undefined') return null;\n const value = new URLSearchParams(window.location.search).get(\n errorParam.name,\n );\n return value ? errorParam.toMessage(value) : null;\n });\n\n const query = useQuery({\n queryKey: ['integration-data', accountId, connectionKey],\n queryFn: async () => {\n const result = await checkConnection({ accountId });\n\n if (!result.success) {\n return { isConnected: false, error: result.error };\n }\n\n return {\n isConnected: true,\n obtainedAt: result.data?.obtainedAt,\n };\n },\n enabled: enabled && !!accountId,\n staleTime: 5 * 60 * 1000,\n refetchOnWindowFocus: false,\n });\n\n const errorParamName = errorParam?.name;\n\n const returnedWithError = oauthError !== null;\n\n // Justified useEffect: after the OAuth redirect lands back on this page —\n // with `?oauth_success=true` OR with the integration's error param — we\n // must (1) strip the transient query params from the URL, so a reload does\n // not re-announce a stale success or re-show a stale error, and (2) on\n // success invalidate the cached connection status so widgets flip to\n // connected without a manual refresh. Both are post-render side effects\n // on external systems (history API + query cache), not derivable during\n // render. The error itself stays in state for this render, so the alert\n // still shows once.\n useEffect(() => {\n if (!oauthJustCompleted && !returnedWithError) return;\n\n const url = new URL(window.location.href);\n url.searchParams.delete('oauth_success');\n\n if (errorParamName) {\n url.searchParams.delete(errorParamName);\n }\n\n window.history.replaceState({}, '', url.pathname + url.search);\n\n if (oauthJustCompleted) {\n queryClient.invalidateQueries({\n queryKey: ['integration-data', accountId, connectionKey],\n });\n }\n }, [\n oauthJustCompleted,\n returnedWithError,\n accountId,\n connectionKey,\n errorParamName,\n queryClient,\n ]);\n\n // Named, not spread: spreading a query result reads every field, so\n // the component re-renders on all of them (TanStack render optimizations).\n return {\n data: query.data,\n error: query.error,\n status: query.status,\n isPending: query.isPending,\n isLoading: query.isLoading,\n isError: query.isError,\n isSuccess: query.isSuccess,\n isFetching: query.isFetching,\n isRefetching: query.isRefetching,\n dataUpdatedAt: query.dataUpdatedAt,\n refetch: query.refetch,\n oauthJustCompleted,\n oauthError,\n };\n}\n\n/**\n * Resolves the gating booleans every OAuth-backed dashboard widget needs:\n *\n * - `enabled` — the integration is active and an account id is present.\n * - `isConnected` — a live OAuth connection exists (access token).\n * - `dataEnabled` — safe to fire the widget's data query (active + connected).\n * - `connectionPending` — still resolving the connection status.\n * - `connectionError` — the connection check itself failed (network/5xx).\n * Distinct from `notConnected`: a transient failure should surface as an\n * error, not as a misleading \"connect X\" prompt.\n * - `notConnected` — activated, resolved without error, but no OAuth\n * connection. The widget should render its \"connect X\" inactive state.\n *\n * The underlying connection check shares one query key across all widgets,\n * so react-query dedupes it to a single request per dashboard load.\n */\nexport type OAuthWidgetGateOptions =\n | (Pick<\n UseOAuthConnectionStatusOptions,\n 'connectionKey' | 'checkConnection'\n > & {\n slug?: never;\n })\n /**\n * The hosted-transport shorthand: for an integration whose connection is\n * checked at `GET /api/integrations/<slug>/oauth/status`, the slug is the\n * only fact the gate needs — the key is `<slug>-connection` by convention\n * and the check is `createPartnerConnectionCheck(slug)`.\n */\n | { slug: string; connectionKey?: never; checkConnection?: never };\n\n/** Pure: the gate options a slug implies. Exported for tests and for widgets that need the key. */\nexport function oauthWidgetGateOptionsFor(\n slug: string,\n): Pick<UseOAuthConnectionStatusOptions, 'connectionKey' | 'checkConnection'> {\n return {\n connectionKey: `${slug}-connection`,\n checkConnection: createPartnerConnectionCheck(slug),\n };\n}\n\nexport function useOAuthWidgetGate(\n accountId: string | undefined,\n integrationActive: boolean,\n options: OAuthWidgetGateOptions,\n) {\n const enabled = integrationActive && !!accountId;\n const resolved =\n options.slug !== undefined\n ? oauthWidgetGateOptionsFor(options.slug)\n : options;\n const query = useOAuthConnectionStatus(accountId ?? '', {\n ...resolved,\n enabled,\n });\n\n const connectionPending = enabled && query.isPending;\n const connectionError = enabled && query.isError;\n const isConnected = query.data?.isConnected === true;\n const dataEnabled = enabled && isConnected;\n // Only treat as \"not connected\" when the check resolved successfully with\n // no token — a query error is an error state, not a disconnected account.\n const notConnected =\n enabled && !connectionPending && !connectionError && !isConnected;\n\n return {\n enabled,\n isConnected,\n connectionPending,\n connectionError,\n dataEnabled,\n notConnected,\n };\n}\n"]}
|
|
@@ -135,7 +135,7 @@ export interface IntegrationMetadata {
|
|
|
135
135
|
* omission. An Integration is any package extending `BaseIntegration`; its
|
|
136
136
|
* kind says who turns it on and whether it needs credentials:
|
|
137
137
|
*
|
|
138
|
-
* '
|
|
138
|
+
* 'feature' — an Ekanos-native capability. Enabled for a Source by a
|
|
139
139
|
* super-admin; no third-party credentials, no activation flow, no
|
|
140
140
|
* marketplace tile. Always declares its own top-level sidebar Section
|
|
141
141
|
* via `getSidebarNav()` and NEVER declares `getWorkspaceTargets()` —
|
|
@@ -151,7 +151,7 @@ export interface IntegrationMetadata {
|
|
|
151
151
|
* a Feature MUST declare a Section and MUST NOT declare a Workspace; a
|
|
152
152
|
* connector MAY declare either or both.
|
|
153
153
|
*/
|
|
154
|
-
kind: '
|
|
154
|
+
kind: 'feature' | 'integration';
|
|
155
155
|
/**
|
|
156
156
|
* Product slugs that MUST be attached to the same Source for this product to
|
|
157
157
|
* function — a hard dependency, not a suggestion.
|
|
@@ -161,7 +161,7 @@ export interface IntegrationMetadata {
|
|
|
161
161
|
* the dependency in both directions ("Requires X" / "Enables Y").
|
|
162
162
|
*
|
|
163
163
|
* Host CI enforces: every slug is registered, nothing requires itself, no
|
|
164
|
-
* cycles, and a `kind: '
|
|
164
|
+
* cycles, and a `kind: 'feature'` may require a `'integration'` but never
|
|
165
165
|
* the reverse.
|
|
166
166
|
*/
|
|
167
167
|
requires?: string[];
|