@or-sdk/idw-skill 1.1.0-beta.4024.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 +142 -0
- package/dist/cjs/IdwSkill.js +82 -0
- package/dist/cjs/IdwSkill.js.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types.js +12 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/IdwSkill.js +68 -0
- package/dist/esm/IdwSkill.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/IdwSkill.d.ts +14 -0
- package/dist/types/IdwSkill.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +57 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +30 -0
- package/src/IdwSkill.ts +142 -0
- package/src/index.ts +2 -0
- package/src/types.ts +85 -0
- package/tsconfig.dev.json +8 -0
- package/tsconfig.esm.json +12 -0
- package/tsconfig.json +7 -0
- package/tsconfig.types.json +11 -0
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Communication Protocol Specification: IDW & Web Skills (v1.0)
|
|
2
|
+
|
|
3
|
+
## 1. Overview
|
|
4
|
+
This document defines the formal messaging protocol for secure, asynchronous communication between the **Intelligent Digital Workforce (IDW)** (Host) and **Web Skills** (Guest) using the HTML5 `postMessage` API.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 2. Terminology
|
|
9
|
+
* **IDW:** Intelligent Digital Workforce (The Host environment).
|
|
10
|
+
* **Skill:** The Web Skill/Micro-app running in an iframe (The Guest).
|
|
11
|
+
* **Event:** A structured object sent via `postMessage`. The term "Event" is used to distinguish protocol actions from chat messages.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 3. Event Structure
|
|
16
|
+
All communication must implement the `IdwEvent` interface.
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
|
|
20
|
+
interface IdwInitPayload {
|
|
21
|
+
orToken: string;
|
|
22
|
+
settings: {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
slug: string;
|
|
26
|
+
accountId: string;
|
|
27
|
+
isPrivate: boolean;
|
|
28
|
+
}
|
|
29
|
+
user?: {
|
|
30
|
+
role: string;
|
|
31
|
+
userId: string; // UUID format
|
|
32
|
+
contactId: string; // UUID format
|
|
33
|
+
email: string;
|
|
34
|
+
firstName: string;
|
|
35
|
+
lastName: string;
|
|
36
|
+
avatarUrl: string;
|
|
37
|
+
phoneNumber: string;
|
|
38
|
+
}
|
|
39
|
+
inputParams?: {
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface SkillResultPayload {
|
|
45
|
+
data: unknown;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface SkillErrorPayload {
|
|
50
|
+
code: string;
|
|
51
|
+
message: string;
|
|
52
|
+
details?: unknown;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface IdwEventMap {
|
|
56
|
+
/** Delivers initial configuration to the Skill */
|
|
57
|
+
"idw:init": IdwInitPayload;
|
|
58
|
+
|
|
59
|
+
/** Used by the Skill to trigger initialization flow */
|
|
60
|
+
"skill:init:request": undefined;
|
|
61
|
+
|
|
62
|
+
/** Signal that the Skill is interactive */
|
|
63
|
+
"skill:ready": undefined;
|
|
64
|
+
|
|
65
|
+
/** Delivery of data/outcome back to the IDW */
|
|
66
|
+
"skill:result": SkillResultPayload;
|
|
67
|
+
|
|
68
|
+
/** Standardized error reporting */
|
|
69
|
+
"skill:error": SkillErrorPayload;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface IdwEvent<K extends keyof IdwEventMap> {
|
|
73
|
+
/** Protocol version (e.g., "1.0") */
|
|
74
|
+
version: "1.0";
|
|
75
|
+
|
|
76
|
+
/** * Event identifier using the 'namespace:action' convention.
|
|
77
|
+
* Namespaces: 'idw:' for Host, 'skill:' for Guest.
|
|
78
|
+
*/
|
|
79
|
+
type: K;
|
|
80
|
+
|
|
81
|
+
/** Optional UUID to track request-response pairs */
|
|
82
|
+
requestId?: string;
|
|
83
|
+
|
|
84
|
+
/** The data payload relevant to the event type */
|
|
85
|
+
payload: IdwEventMap[K];
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 4. Initialization Lifecycle (Pull-based Handshake)
|
|
92
|
+
To ensure the Skill is fully loaded and listening before data is sent, the Skill initiates the handshake.
|
|
93
|
+
|
|
94
|
+
| Step | Sender | Event Type | Description |
|
|
95
|
+
| :--- | :--- | :--- | :--- |
|
|
96
|
+
| 1 | **Skill** | `skill:init:request` | Skill has loaded its JS and is ready to receive config. |
|
|
97
|
+
| 2 | **IDW** | `idw:init` | IDW provides initial context, tokens, and settings. |
|
|
98
|
+
| 3 | **Skill** | `skill:ready` | Skill confirms initialization is complete and UI is ready. |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 5. Event Naming & Required Types
|
|
103
|
+
|
|
104
|
+
### Required Events
|
|
105
|
+
* `skill:init:request`: Used by the Skill to trigger the initialization flow.
|
|
106
|
+
* `idw:init`: Delivers initial configuration to the Skill.
|
|
107
|
+
* `skill:ready`: Signal that the Skill is interactive.
|
|
108
|
+
* `skill:result`: Delivery of data/outcome back to the IDW.
|
|
109
|
+
* `skill:error`: Standardized error reporting.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 6. Security & Origin Validation
|
|
114
|
+
To prevent unauthorized access or data leakage, the following measures are mandatory:
|
|
115
|
+
|
|
116
|
+
* **Target Origin:** Never use `postMessage(data, '*')`. Always specify the exact target origin of the recipient.
|
|
117
|
+
* **Payload Sanitization:** Treat all `payload` data as untrusted and validate it before use.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 7. Error Handling
|
|
122
|
+
Errors from the Skill should be communicated to the IDW using a consistent format.
|
|
123
|
+
|
|
124
|
+
**Example `skill:error` Payload:**
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"version": "1.0",
|
|
128
|
+
"type": "skill:error",
|
|
129
|
+
"requestId": "abc-123",
|
|
130
|
+
"payload": {
|
|
131
|
+
"code": "VALIDATION_FAILED",
|
|
132
|
+
"message": "Required field 'userId' is missing.",
|
|
133
|
+
"retryable": false
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 8. Versioning
|
|
141
|
+
* **Version Field:** Every event must include the `"version": "1.0"` string.
|
|
142
|
+
* **Breaking Changes:** Any change that breaks backward compatibility will increment the major version to `2.0`.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdwSkill = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
var PROTOCOL_VERSION = '1.0';
|
|
6
|
+
var IdwSkill = (function () {
|
|
7
|
+
function IdwSkill(params) {
|
|
8
|
+
this._initData = null;
|
|
9
|
+
var targetOrigin = params.targetOrigin;
|
|
10
|
+
if (!targetOrigin) {
|
|
11
|
+
throw new Error('targetOrigin is required');
|
|
12
|
+
}
|
|
13
|
+
this.targetOrigin = targetOrigin;
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(IdwSkill.prototype, "orToken", {
|
|
16
|
+
get: function () {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return (_b = (_a = this._initData) === null || _a === void 0 ? void 0 : _a.orToken) !== null && _b !== void 0 ? _b : null;
|
|
19
|
+
},
|
|
20
|
+
enumerable: false,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(IdwSkill.prototype, "initData", {
|
|
24
|
+
get: function () {
|
|
25
|
+
return this._initData;
|
|
26
|
+
},
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
IdwSkill.prototype.init = function () {
|
|
31
|
+
var _this = this;
|
|
32
|
+
return new Promise(function (resolve) {
|
|
33
|
+
var handleMessage = function (event) {
|
|
34
|
+
if (event.origin !== _this.targetOrigin) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
var data = event.data;
|
|
38
|
+
if ((data === null || data === void 0 ? void 0 : data.version) === PROTOCOL_VERSION && (data === null || data === void 0 ? void 0 : data.type) === types_1.IdwEventType.Init) {
|
|
39
|
+
window.removeEventListener('message', handleMessage);
|
|
40
|
+
_this._initData = data.payload;
|
|
41
|
+
resolve(data.payload);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
window.addEventListener('message', handleMessage);
|
|
45
|
+
_this.postMessage({
|
|
46
|
+
version: PROTOCOL_VERSION,
|
|
47
|
+
type: types_1.IdwEventType.SkillInitRequest,
|
|
48
|
+
payload: undefined,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
IdwSkill.prototype.ready = function (requestId) {
|
|
53
|
+
this.postMessage({
|
|
54
|
+
version: PROTOCOL_VERSION,
|
|
55
|
+
type: types_1.IdwEventType.SkillReady,
|
|
56
|
+
requestId: requestId,
|
|
57
|
+
payload: undefined,
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
IdwSkill.prototype.sendResult = function (payload, requestId) {
|
|
61
|
+
this.postMessage({
|
|
62
|
+
version: PROTOCOL_VERSION,
|
|
63
|
+
type: types_1.IdwEventType.SkillResult,
|
|
64
|
+
requestId: requestId,
|
|
65
|
+
payload: payload,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
IdwSkill.prototype.sendError = function (payload, requestId) {
|
|
69
|
+
this.postMessage({
|
|
70
|
+
version: PROTOCOL_VERSION,
|
|
71
|
+
type: types_1.IdwEventType.SkillError,
|
|
72
|
+
requestId: requestId,
|
|
73
|
+
payload: payload,
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
IdwSkill.prototype.postMessage = function (event) {
|
|
77
|
+
window.parent.postMessage(event, this.targetOrigin);
|
|
78
|
+
};
|
|
79
|
+
return IdwSkill;
|
|
80
|
+
}());
|
|
81
|
+
exports.IdwSkill = IdwSkill;
|
|
82
|
+
//# sourceMappingURL=IdwSkill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IdwSkill.js","sourceRoot":"","sources":["../../src/IdwSkill.ts"],"names":[],"mappings":";;;AAAA,iCASiB;AAEjB,IAAM,gBAAgB,GAAoB,KAAK,CAAC;AAyBhD;IAIE,kBAAY,MAAsB;QAF1B,cAAS,GAA0B,IAAI,CAAC;QAGtC,IAAA,YAAY,GAAK,MAAM,aAAX,CAAY;QAEhC,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAGD,sBAAI,6BAAO;aAAX;;YACE,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,OAAO,mCAAI,IAAI,CAAC;QACzC,CAAC;;;OAAA;IAGD,sBAAI,8BAAQ;aAAZ;YACE,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;;;OAAA;IASD,uBAAI,GAAJ;QAAA,iBAwBC;QAvBC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO;YACzB,IAAM,aAAa,GAAG,UAAC,KAAmB;gBACxC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAI,CAAC,YAAY,EAAE,CAAC;oBACvC,OAAO;gBACT,CAA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YACT,OAAO,SAAA;SACR,CAAC,CAAC;IACL,CAAC;IAEO,8BAAW,GAAnB,UAAiD,KAAkB;QACjE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACtD,CAAC;IACH,eAAC;AAAD,CAAC,AAzGD,IAyGC;AAzGY,4BAAQ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.IdwSkill = void 0;
|
|
18
|
+
var IdwSkill_1 = require("./IdwSkill");
|
|
19
|
+
Object.defineProperty(exports, "IdwSkill", { enumerable: true, get: function () { return IdwSkill_1.IdwSkill; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,0CAAwB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdwEventType = void 0;
|
|
4
|
+
var IdwEventType;
|
|
5
|
+
(function (IdwEventType) {
|
|
6
|
+
IdwEventType["SkillInitRequest"] = "skill:init:request";
|
|
7
|
+
IdwEventType["Init"] = "idw:init";
|
|
8
|
+
IdwEventType["SkillReady"] = "skill:ready";
|
|
9
|
+
IdwEventType["SkillResult"] = "skill:result";
|
|
10
|
+
IdwEventType["SkillError"] = "skill:error";
|
|
11
|
+
})(IdwEventType || (exports.IdwEventType = IdwEventType = {}));
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAmDA,IAAY,YAWX;AAXD,WAAY,YAAY;IAEtB,uDAAuC,CAAA;IAEvC,iCAAiB,CAAA;IAEjB,0CAA0B,CAAA;IAE1B,4CAA4B,CAAA;IAE5B,0CAA0B,CAAA;AAC5B,CAAC,EAXW,YAAY,4BAAZ,YAAY,QAWvB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { IdwEventType, } from './types';
|
|
2
|
+
const PROTOCOL_VERSION = '1.0';
|
|
3
|
+
export class IdwSkill {
|
|
4
|
+
constructor(params) {
|
|
5
|
+
this._initData = null;
|
|
6
|
+
const { targetOrigin } = params;
|
|
7
|
+
if (!targetOrigin) {
|
|
8
|
+
throw new Error('targetOrigin is required');
|
|
9
|
+
}
|
|
10
|
+
this.targetOrigin = targetOrigin;
|
|
11
|
+
}
|
|
12
|
+
get orToken() {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
return (_b = (_a = this._initData) === null || _a === void 0 ? void 0 : _a.orToken) !== null && _b !== void 0 ? _b : null;
|
|
15
|
+
}
|
|
16
|
+
get initData() {
|
|
17
|
+
return this._initData;
|
|
18
|
+
}
|
|
19
|
+
init() {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const handleMessage = (event) => {
|
|
22
|
+
if (event.origin !== this.targetOrigin) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const data = event.data;
|
|
26
|
+
if ((data === null || data === void 0 ? void 0 : data.version) === PROTOCOL_VERSION && (data === null || data === void 0 ? void 0 : data.type) === IdwEventType.Init) {
|
|
27
|
+
window.removeEventListener('message', handleMessage);
|
|
28
|
+
this._initData = data.payload;
|
|
29
|
+
resolve(data.payload);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
window.addEventListener('message', handleMessage);
|
|
33
|
+
this.postMessage({
|
|
34
|
+
version: PROTOCOL_VERSION,
|
|
35
|
+
type: IdwEventType.SkillInitRequest,
|
|
36
|
+
payload: undefined,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
ready(requestId) {
|
|
41
|
+
this.postMessage({
|
|
42
|
+
version: PROTOCOL_VERSION,
|
|
43
|
+
type: IdwEventType.SkillReady,
|
|
44
|
+
requestId,
|
|
45
|
+
payload: undefined,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
sendResult(payload, requestId) {
|
|
49
|
+
this.postMessage({
|
|
50
|
+
version: PROTOCOL_VERSION,
|
|
51
|
+
type: IdwEventType.SkillResult,
|
|
52
|
+
requestId,
|
|
53
|
+
payload,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
sendError(payload, requestId) {
|
|
57
|
+
this.postMessage({
|
|
58
|
+
version: PROTOCOL_VERSION,
|
|
59
|
+
type: IdwEventType.SkillError,
|
|
60
|
+
requestId,
|
|
61
|
+
payload,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
postMessage(event) {
|
|
65
|
+
window.parent.postMessage(event, this.targetOrigin);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=IdwSkill.js.map
|
|
@@ -0,0 +1 @@
|
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B,CAAC;YACH,CAAC,CAAC;YAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YAElD,IAAI,CAAC,WAAW,CAAgC;gBAC9C,OAAO,EAAE,gBAAgB;gBACzB,IAAI,EAAE,YAAY,CAAC,gBAAgB;gBACnC,OAAO,EAAE,SAAS;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAQD,KAAK,CAAC,SAAkB;QACtB,IAAI,CAAC,WAAW,CAA0B;YACxC,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE,YAAY,CAAC,UAAU;YAC7B,SAAS;YACT,OAAO,EAAE,SAAS;SACnB,CAAC,CAAC;IACL,CAAC;IAQD,UAAU,CAAC,OAA2B,EAAE,SAAkB;QACxD,IAAI,CAAC,WAAW,CAA2B;YACzC,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE,YAAY,CAAC,WAAW;YAC9B,SAAS;YACT,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAQD,SAAS,CAAC,OAA0B,EAAE,SAAkB;QACtD,IAAI,CAAC,WAAW,CAA0B;YACxC,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE,YAAY,CAAC,UAAU;YAC7B,SAAS;YACT,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAEO,WAAW,CAA8B,KAAkB;QACjE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var IdwEventType;
|
|
2
|
+
(function (IdwEventType) {
|
|
3
|
+
IdwEventType["SkillInitRequest"] = "skill:init:request";
|
|
4
|
+
IdwEventType["Init"] = "idw:init";
|
|
5
|
+
IdwEventType["SkillReady"] = "skill:ready";
|
|
6
|
+
IdwEventType["SkillResult"] = "skill:result";
|
|
7
|
+
IdwEventType["SkillError"] = "skill:error";
|
|
8
|
+
})(IdwEventType || (IdwEventType = {}));
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAmDA,MAAM,CAAN,IAAY,YAWX;AAXD,WAAY,YAAY;IAEtB,uDAAuC,CAAA;IAEvC,iCAAiB,CAAA;IAEjB,0CAA0B,CAAA;IAE1B,4CAA4B,CAAA;IAE5B,0CAA0B,CAAA;AAC5B,CAAC,EAXW,YAAY,KAAZ,YAAY,QAWvB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IdwInitPayload, IdwSkillConfig, SkillErrorPayload, SkillResultPayload } from './types';
|
|
2
|
+
export declare class IdwSkill {
|
|
3
|
+
private readonly targetOrigin;
|
|
4
|
+
private _initData;
|
|
5
|
+
constructor(params: IdwSkillConfig);
|
|
6
|
+
get orToken(): string | null;
|
|
7
|
+
get initData(): IdwInitPayload | null;
|
|
8
|
+
init(): Promise<IdwInitPayload>;
|
|
9
|
+
ready(requestId?: string): void;
|
|
10
|
+
sendResult(payload: SkillResultPayload, requestId?: string): void;
|
|
11
|
+
sendError(payload: SkillErrorPayload, requestId?: string): void;
|
|
12
|
+
private postMessage;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=IdwSkill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IdwSkill.d.ts","sourceRoot":"","sources":["../../src/IdwSkill.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,cAAc,EACd,cAAc,EAEd,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AA2BjB,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,SAAS,CAA+B;gBAEpC,MAAM,EAAE,cAAc;IAWlC,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAGD,IAAI,QAAQ,IAAI,cAAc,GAAG,IAAI,CAEpC;IASD,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC;IAgC/B,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAe/B,UAAU,CAAC,OAAO,EAAE,kBAAkB,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAejE,SAAS,CAAC,OAAO,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAS/D,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type ProtocolVersion = '1.0';
|
|
2
|
+
export type IdwSkillConfig = {
|
|
3
|
+
targetOrigin: string;
|
|
4
|
+
};
|
|
5
|
+
export interface IdwSkillSettings {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
slug: string;
|
|
9
|
+
accountId: string;
|
|
10
|
+
isPrivate: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface IdwSkillUser {
|
|
13
|
+
role: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
contactId: string;
|
|
16
|
+
email: string;
|
|
17
|
+
firstName: string;
|
|
18
|
+
lastName: string;
|
|
19
|
+
avatarUrl: string;
|
|
20
|
+
phoneNumber: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IdwInitPayload {
|
|
23
|
+
orToken: string;
|
|
24
|
+
settings: IdwSkillSettings;
|
|
25
|
+
user?: IdwSkillUser;
|
|
26
|
+
inputParams?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export interface SkillResultPayload {
|
|
29
|
+
data: unknown;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
export interface SkillErrorPayload {
|
|
33
|
+
code: string;
|
|
34
|
+
message: string;
|
|
35
|
+
details?: unknown;
|
|
36
|
+
}
|
|
37
|
+
export declare enum IdwEventType {
|
|
38
|
+
SkillInitRequest = "skill:init:request",
|
|
39
|
+
Init = "idw:init",
|
|
40
|
+
SkillReady = "skill:ready",
|
|
41
|
+
SkillResult = "skill:result",
|
|
42
|
+
SkillError = "skill:error"
|
|
43
|
+
}
|
|
44
|
+
export interface IdwEventMap {
|
|
45
|
+
[IdwEventType.SkillInitRequest]: undefined;
|
|
46
|
+
[IdwEventType.Init]: IdwInitPayload;
|
|
47
|
+
[IdwEventType.SkillReady]: undefined;
|
|
48
|
+
[IdwEventType.SkillResult]: SkillResultPayload;
|
|
49
|
+
[IdwEventType.SkillError]: SkillErrorPayload;
|
|
50
|
+
}
|
|
51
|
+
export interface IdwEvent<K extends keyof IdwEventMap> {
|
|
52
|
+
version: ProtocolVersion;
|
|
53
|
+
type: K;
|
|
54
|
+
requestId?: string;
|
|
55
|
+
payload: IdwEventMap[K];
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC;AAEpC,MAAM,MAAM,cAAc,GAAG;IAO3B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAA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nD,OAAO,EAAE,eAAe,CAAC;IAKzB,IAAI,EAAE,CAAC,CAAC;IAER,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACzB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@or-sdk/idw-skill",
|
|
3
|
+
"version": "1.1.0-beta.4024.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "pnpm clean && concurrently 'pnpm:build:*(!watch)'",
|
|
10
|
+
"build:cjs": "tsc --project tsconfig.json",
|
|
11
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
12
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
13
|
+
"build:watch": "concurrently 'pnpm:build:watch:*'",
|
|
14
|
+
"build:watch:cjs": "tsc --project tsconfig.json -w",
|
|
15
|
+
"build:watch:esm": "tsc --project tsconfig.esm.json -w",
|
|
16
|
+
"build:watch:types": "tsc --project tsconfig.types.json -w",
|
|
17
|
+
"clean": "rm -rf ./dist",
|
|
18
|
+
"dev": "pnpm build:watch:esm"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@or-sdk/base": "^0.44.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"concurrently": "9.0.1",
|
|
25
|
+
"typescript": "5.6.2"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/IdwSkill.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IdwEvent,
|
|
3
|
+
IdwEventMap,
|
|
4
|
+
IdwEventType,
|
|
5
|
+
IdwInitPayload,
|
|
6
|
+
IdwSkillConfig,
|
|
7
|
+
ProtocolVersion,
|
|
8
|
+
SkillErrorPayload,
|
|
9
|
+
SkillResultPayload,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
const PROTOCOL_VERSION: ProtocolVersion = '1.0';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* OneReach IdwSkill — client for Web Skills running inside an IDW iframe.
|
|
16
|
+
*
|
|
17
|
+
* ## Installation:
|
|
18
|
+
* ```
|
|
19
|
+
* $ npm i @or-sdk/idw-skill
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ## Usage:
|
|
23
|
+
* ```ts
|
|
24
|
+
* const sdk = new IdwSkill({ targetOrigin: 'https://idw.edison.onereach.ai' });
|
|
25
|
+
*
|
|
26
|
+
* // 1. Trigger the handshake and wait for IDW configuration
|
|
27
|
+
* const initData = await sdk.init();
|
|
28
|
+
*
|
|
29
|
+
* // 2. Render your UI using initData, then signal readiness
|
|
30
|
+
* sdk.ready();
|
|
31
|
+
*
|
|
32
|
+
* // 3. Later — report a result or an error back to the IDW
|
|
33
|
+
* sdk.sendResult({ data: { answer: 42 } });
|
|
34
|
+
* sdk.sendError({ code: 'VALIDATION_FAILED', message: 'userId is missing' });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export class IdwSkill {
|
|
38
|
+
private readonly targetOrigin: string;
|
|
39
|
+
private _initData: IdwInitPayload | null = null;
|
|
40
|
+
|
|
41
|
+
constructor(params: IdwSkillConfig) {
|
|
42
|
+
const { targetOrigin } = params;
|
|
43
|
+
|
|
44
|
+
if (!targetOrigin) {
|
|
45
|
+
throw new Error('targetOrigin is required');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.targetOrigin = targetOrigin;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The orToken received from IDW during init, or null before init completes. */
|
|
52
|
+
get orToken(): string | null {
|
|
53
|
+
return this._initData?.orToken ?? null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The full payload received from IDW during init, or null before init completes. */
|
|
57
|
+
get initData(): IdwInitPayload | null {
|
|
58
|
+
return this._initData;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Initiates the pull-based handshake with the IDW host.
|
|
63
|
+
*
|
|
64
|
+
* Sends `skill:init:request` to the parent frame and returns a Promise
|
|
65
|
+
* that resolves with the `IdwInitPayload` once the IDW responds with
|
|
66
|
+
* `idw:init`. Only messages originating from `targetOrigin` are accepted.
|
|
67
|
+
*/
|
|
68
|
+
init(): Promise<IdwInitPayload> {
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
const handleMessage = (event: MessageEvent) => {
|
|
71
|
+
if (event.origin !== this.targetOrigin) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const data = event.data as IdwEvent<IdwEventType.Init>;
|
|
76
|
+
|
|
77
|
+
if (data?.version === PROTOCOL_VERSION && data?.type === IdwEventType.Init) {
|
|
78
|
+
window.removeEventListener('message', handleMessage);
|
|
79
|
+
this._initData = data.payload;
|
|
80
|
+
resolve(data.payload);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
window.addEventListener('message', handleMessage);
|
|
85
|
+
|
|
86
|
+
this.postMessage<IdwEventType.SkillInitRequest>({
|
|
87
|
+
version: PROTOCOL_VERSION,
|
|
88
|
+
type: IdwEventType.SkillInitRequest,
|
|
89
|
+
payload: undefined,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Signals to the IDW that the Skill UI is fully rendered and interactive.
|
|
96
|
+
* Call this after `init()` resolves and your component tree is ready.
|
|
97
|
+
*
|
|
98
|
+
* @param requestId - Optional UUID to correlate with a prior IDW request.
|
|
99
|
+
*/
|
|
100
|
+
ready(requestId?: string): void {
|
|
101
|
+
this.postMessage<IdwEventType.SkillReady>({
|
|
102
|
+
version: PROTOCOL_VERSION,
|
|
103
|
+
type: IdwEventType.SkillReady,
|
|
104
|
+
requestId,
|
|
105
|
+
payload: undefined,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Delivers a result payload back to the IDW.
|
|
111
|
+
*
|
|
112
|
+
* @param payload - The result data to send.
|
|
113
|
+
* @param requestId - Optional UUID to correlate with a prior IDW request.
|
|
114
|
+
*/
|
|
115
|
+
sendResult(payload: SkillResultPayload, requestId?: string): void {
|
|
116
|
+
this.postMessage<IdwEventType.SkillResult>({
|
|
117
|
+
version: PROTOCOL_VERSION,
|
|
118
|
+
type: IdwEventType.SkillResult,
|
|
119
|
+
requestId,
|
|
120
|
+
payload,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Reports a standardized error to the IDW.
|
|
126
|
+
*
|
|
127
|
+
* @param payload - The error details (code, message, optional details).
|
|
128
|
+
* @param requestId - Optional UUID to correlate with a prior IDW request.
|
|
129
|
+
*/
|
|
130
|
+
sendError(payload: SkillErrorPayload, requestId?: string): void {
|
|
131
|
+
this.postMessage<IdwEventType.SkillError>({
|
|
132
|
+
version: PROTOCOL_VERSION,
|
|
133
|
+
type: IdwEventType.SkillError,
|
|
134
|
+
requestId,
|
|
135
|
+
payload,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private postMessage<K extends keyof IdwEventMap>(event: IdwEvent<K>): void {
|
|
140
|
+
window.parent.postMessage(event, this.targetOrigin);
|
|
141
|
+
}
|
|
142
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export type ProtocolVersion = '1.0';
|
|
2
|
+
|
|
3
|
+
export type IdwSkillConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* The exact origin of the IDW host (e.g. 'https://idw.edison.onereach.ai').
|
|
6
|
+
* Used as the targetOrigin for all outgoing postMessage calls and to
|
|
7
|
+
* validate the origin of every incoming message.
|
|
8
|
+
* Never use '*' — that would be a security vulnerability.
|
|
9
|
+
*/
|
|
10
|
+
targetOrigin: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export interface IdwSkillSettings {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
slug: string;
|
|
17
|
+
accountId: string;
|
|
18
|
+
isPrivate: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IdwSkillUser {
|
|
22
|
+
role: string;
|
|
23
|
+
/** UUID format */
|
|
24
|
+
userId: string;
|
|
25
|
+
/** UUID format */
|
|
26
|
+
contactId: string;
|
|
27
|
+
email: string;
|
|
28
|
+
firstName: string;
|
|
29
|
+
lastName: string;
|
|
30
|
+
avatarUrl: string;
|
|
31
|
+
phoneNumber: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IdwInitPayload {
|
|
35
|
+
orToken: string;
|
|
36
|
+
settings: IdwSkillSettings;
|
|
37
|
+
user?: IdwSkillUser;
|
|
38
|
+
inputParams?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface SkillResultPayload {
|
|
42
|
+
data: unknown;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface SkillErrorPayload {
|
|
47
|
+
code: string;
|
|
48
|
+
message: string;
|
|
49
|
+
details?: unknown;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export enum IdwEventType {
|
|
53
|
+
/** Used by the Skill to trigger the initialization flow */
|
|
54
|
+
SkillInitRequest = 'skill:init:request',
|
|
55
|
+
/** Delivers initial configuration to the Skill */
|
|
56
|
+
Init = 'idw:init',
|
|
57
|
+
/** Signal that the Skill is interactive */
|
|
58
|
+
SkillReady = 'skill:ready',
|
|
59
|
+
/** Delivery of data/outcome back to the IDW */
|
|
60
|
+
SkillResult = 'skill:result',
|
|
61
|
+
/** Standardized error reporting */
|
|
62
|
+
SkillError = 'skill:error',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface IdwEventMap {
|
|
66
|
+
[IdwEventType.SkillInitRequest]: undefined;
|
|
67
|
+
[IdwEventType.Init]: IdwInitPayload;
|
|
68
|
+
[IdwEventType.SkillReady]: undefined;
|
|
69
|
+
[IdwEventType.SkillResult]: SkillResultPayload;
|
|
70
|
+
[IdwEventType.SkillError]: SkillErrorPayload;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface IdwEvent<K extends keyof IdwEventMap> {
|
|
74
|
+
/** Protocol version */
|
|
75
|
+
version: ProtocolVersion;
|
|
76
|
+
/**
|
|
77
|
+
* Event identifier using the 'namespace:action' convention.
|
|
78
|
+
* Namespaces: 'idw:' for Host, 'skill:' for Guest.
|
|
79
|
+
*/
|
|
80
|
+
type: K;
|
|
81
|
+
/** Optional UUID to track request-response pairs */
|
|
82
|
+
requestId?: string;
|
|
83
|
+
/** The data payload relevant to the event type */
|
|
84
|
+
payload: IdwEventMap[K];
|
|
85
|
+
}
|
package/tsconfig.json
ADDED