@rehers/rehers-roleplay-sdk 2.5.5 → 2.5.7
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 +2 -4
- package/index.d.ts +4 -23
- package/package.json +2 -1
- package/react.d.ts +1 -1
- package/react.js +20 -46
- package/roleplay-sdk.js +6 -24
package/README.md
CHANGED
|
@@ -18,9 +18,9 @@ Production flow:
|
|
|
18
18
|
|
|
19
19
|
1. Your backend requests a short-lived `userToken` from `POST /api/seamless/auth/user-token`
|
|
20
20
|
2. Your frontend receives that `userToken`
|
|
21
|
-
3. You pass `
|
|
21
|
+
3. You pass `userToken` into the SDK
|
|
22
22
|
|
|
23
|
-
The browser should not mint sessions from raw
|
|
23
|
+
The browser should not mint sessions from raw identity fields in production.
|
|
24
24
|
|
|
25
25
|
```tsx
|
|
26
26
|
import { SeamlessRoleplayProvider } from "@rehers/rehers-roleplay-sdk/react";
|
|
@@ -30,7 +30,6 @@ function App() {
|
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<SeamlessRoleplayProvider
|
|
33
|
-
publishableKey="pk_live_..."
|
|
34
33
|
userToken={userToken}
|
|
35
34
|
onReady={() => console.log("Roleplay SDK ready")}
|
|
36
35
|
onError={(err) => console.error("Roleplay SDK error", err)}
|
|
@@ -222,7 +221,6 @@ import "@rehers/rehers-roleplay-sdk";
|
|
|
222
221
|
|
|
223
222
|
// Initialize once
|
|
224
223
|
SeamlessRoleplay.init({
|
|
225
|
-
publishableKey: "pk_live_...",
|
|
226
224
|
userToken: "...",
|
|
227
225
|
onReady() { console.log("ready"); },
|
|
228
226
|
});
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
interface SeamlessRoleplayInitBase {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
/** Optional user role for syncing permissions ("owner" | "admin" | "member") */
|
|
5
|
-
userRole?: "owner" | "admin" | "member";
|
|
6
|
-
/** Optional short-lived signed JWT for identity verification */
|
|
7
|
-
userToken?: string;
|
|
2
|
+
/** Short-lived signed JWT minted by your backend for the signed-in user */
|
|
3
|
+
userToken: string;
|
|
8
4
|
/** Override the app origin — where the iframe loads from (for dev/testing only) */
|
|
9
5
|
origin?: string;
|
|
10
6
|
/** Called when the SDK session is ready */
|
|
@@ -13,22 +9,7 @@ interface SeamlessRoleplayInitBase {
|
|
|
13
9
|
onError?: (error: { code: string; message: string }) => void;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export type SeamlessRoleplayInitOptions =
|
|
17
|
-
| (SeamlessRoleplayInitBase & {
|
|
18
|
-
/** Preferred production auth path: signed Seamless bootstrap token */
|
|
19
|
-
userToken: string;
|
|
20
|
-
/** Optional fallback fields kept for local demos/internal tools */
|
|
21
|
-
userId?: string;
|
|
22
|
-
userEmail?: string;
|
|
23
|
-
})
|
|
24
|
-
| (SeamlessRoleplayInitBase & {
|
|
25
|
-
/** Legacy/demo fallback path when no signed token is available */
|
|
26
|
-
userToken?: string;
|
|
27
|
-
/** Logged-in Seamless user ID. Pass String(me.id) from GET /api/users/me */
|
|
28
|
-
userId: string;
|
|
29
|
-
/** Logged-in Seamless user email. Pass me.username from GET /api/users/me */
|
|
30
|
-
userEmail: string;
|
|
31
|
-
});
|
|
12
|
+
export type SeamlessRoleplayInitOptions = SeamlessRoleplayInitBase;
|
|
32
13
|
|
|
33
14
|
export interface SeamlessRoleplayOpenData {
|
|
34
15
|
/** Full name of the contact */
|
|
@@ -83,7 +64,7 @@ export interface AddToScenarioOptions {
|
|
|
83
64
|
}
|
|
84
65
|
|
|
85
66
|
export interface SeamlessRoleplaySDK {
|
|
86
|
-
/** Initialize the SDK with a
|
|
67
|
+
/** Initialize the SDK with a short-lived user token. */
|
|
87
68
|
init(options: SeamlessRoleplayInitOptions): void;
|
|
88
69
|
/** Open the roleplay modal for a contact (dialog mode). */
|
|
89
70
|
open(data: SeamlessRoleplayOpenData): void;
|
package/package.json
CHANGED
package/react.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface SeamlessRoleplayContextValue {
|
|
|
13
13
|
export type SeamlessRoleplayProviderProps = SeamlessRoleplayInitOptions & {
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
};
|
|
16
|
-
export declare function SeamlessRoleplayProvider({
|
|
16
|
+
export declare function SeamlessRoleplayProvider({ userToken, origin, onReady, onError, children, }: SeamlessRoleplayProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
17
17
|
export declare function useSeamlessRoleplay(): SeamlessRoleplayContextValue;
|
|
18
18
|
export interface RoleplayDialogProps {
|
|
19
19
|
open: boolean;
|
package/react.js
CHANGED
|
@@ -22,7 +22,7 @@ function getSDK() {
|
|
|
22
22
|
}
|
|
23
23
|
const SeamlessRoleplayContext = createContext(null);
|
|
24
24
|
let providerMountCount = 0;
|
|
25
|
-
export function SeamlessRoleplayProvider({
|
|
25
|
+
export function SeamlessRoleplayProvider({ userToken, origin, onReady, onError, children, }) {
|
|
26
26
|
const [state, setState] = useState({ isReady: false, error: null });
|
|
27
27
|
const mountedRef = useRef(false);
|
|
28
28
|
const onReadyRef = useCallbackRef(onReady);
|
|
@@ -36,57 +36,31 @@ export function SeamlessRoleplayProvider({ publishableKey, userId, userEmail, us
|
|
|
36
36
|
}
|
|
37
37
|
mountedRef.current = true;
|
|
38
38
|
setState({ isReady: false, error: null });
|
|
39
|
-
const initOptions =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return;
|
|
58
|
-
setState({ isReady: false, error: err });
|
|
59
|
-
(_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, err);
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
: {
|
|
63
|
-
publishableKey,
|
|
64
|
-
userId: userId || "",
|
|
65
|
-
userEmail: userEmail || "",
|
|
66
|
-
userRole,
|
|
67
|
-
origin,
|
|
68
|
-
onReady: () => {
|
|
69
|
-
var _a;
|
|
70
|
-
if (!mountedRef.current)
|
|
71
|
-
return;
|
|
72
|
-
setState({ isReady: true, error: null });
|
|
73
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
74
|
-
},
|
|
75
|
-
onError: (err) => {
|
|
76
|
-
var _a;
|
|
77
|
-
if (!mountedRef.current)
|
|
78
|
-
return;
|
|
79
|
-
setState({ isReady: false, error: err });
|
|
80
|
-
(_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, err);
|
|
81
|
-
},
|
|
82
|
-
};
|
|
39
|
+
const initOptions = {
|
|
40
|
+
userToken,
|
|
41
|
+
origin,
|
|
42
|
+
onReady: () => {
|
|
43
|
+
var _a;
|
|
44
|
+
if (!mountedRef.current)
|
|
45
|
+
return;
|
|
46
|
+
setState({ isReady: true, error: null });
|
|
47
|
+
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
48
|
+
},
|
|
49
|
+
onError: (err) => {
|
|
50
|
+
var _a;
|
|
51
|
+
if (!mountedRef.current)
|
|
52
|
+
return;
|
|
53
|
+
setState({ isReady: false, error: err });
|
|
54
|
+
(_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, err);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
83
57
|
sdk.init(initOptions);
|
|
84
58
|
return () => {
|
|
85
59
|
mountedRef.current = false;
|
|
86
60
|
providerMountCount--;
|
|
87
61
|
sdk.destroy();
|
|
88
62
|
};
|
|
89
|
-
}, [sdk,
|
|
63
|
+
}, [sdk, userToken, origin]);
|
|
90
64
|
const contextValue = useMemo(() => ({ ...state, sdk }), [state, sdk]);
|
|
91
65
|
return (_jsx(SeamlessRoleplayContext.Provider, { value: contextValue, children: children }));
|
|
92
66
|
}
|
package/roleplay-sdk.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SeamlessRoleplay SDK v2
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* User-token auth model. No build step required.
|
|
5
5
|
*
|
|
6
6
|
* Usage:
|
|
7
|
-
* SeamlessRoleplay.init({
|
|
7
|
+
* SeamlessRoleplay.init({ userToken: 'jwt...' });
|
|
8
8
|
* SeamlessRoleplay.open({ name: '...', domain: '...', company: '...', title: '...' });
|
|
9
9
|
*/
|
|
10
10
|
(function () {
|
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
var SDK_LOG_PREFIX = "[SeamlessRoleplay]";
|
|
17
17
|
|
|
18
18
|
// ── Auth state ────────────────────────────────────────────────────
|
|
19
|
-
var publishableKey = null;
|
|
20
|
-
var userId = null;
|
|
21
|
-
var userEmail = null;
|
|
22
|
-
var userRole = null;
|
|
23
19
|
var userToken = null;
|
|
24
20
|
var paymentLink = null;
|
|
25
21
|
var appOrigin = null;
|
|
@@ -114,15 +110,12 @@
|
|
|
114
110
|
|
|
115
111
|
var requestPromise = new Promise(function (resolve, reject) {
|
|
116
112
|
var url = getApiOrigin() + "/api/sdk/session";
|
|
117
|
-
var body = userToken
|
|
118
|
-
? { userToken: userToken }
|
|
119
|
-
: { userId: userId, userEmail: userEmail, userRole: userRole };
|
|
113
|
+
var body = { userToken: userToken };
|
|
120
114
|
|
|
121
115
|
var xhr = new XMLHttpRequest();
|
|
122
116
|
activeSessionXhr = xhr;
|
|
123
117
|
xhr.open("POST", url, true);
|
|
124
118
|
xhr.setRequestHeader("Content-Type", "application/json");
|
|
125
|
-
xhr.setRequestHeader("X-Publishable-Key", publishableKey);
|
|
126
119
|
xhr.withCredentials = false;
|
|
127
120
|
xhr.timeout = SESSION_TIMEOUT_MS;
|
|
128
121
|
|
|
@@ -274,8 +267,6 @@
|
|
|
274
267
|
var msg = {
|
|
275
268
|
type: "seamless-add-to-scenario-init",
|
|
276
269
|
sessionToken: sessionToken,
|
|
277
|
-
publishableKey: publishableKey,
|
|
278
|
-
userId: userId,
|
|
279
270
|
contacts: atsContacts,
|
|
280
271
|
};
|
|
281
272
|
if (paymentLink) msg.paymentLink = paymentLink;
|
|
@@ -460,18 +451,17 @@
|
|
|
460
451
|
|
|
461
452
|
var SeamlessRoleplay = {
|
|
462
453
|
/**
|
|
463
|
-
* Initialize the SDK with a
|
|
454
|
+
* Initialize the SDK with a short-lived user token.
|
|
464
455
|
*/
|
|
465
456
|
init: function (opts) {
|
|
466
457
|
try {
|
|
467
458
|
var initVersion = activeInitVersion + 1;
|
|
468
459
|
var hasUserToken = !!(opts && opts.userToken && String(opts.userToken).trim());
|
|
469
|
-
var hasLegacyIdentity = !!(opts && opts.userId && opts.userEmail);
|
|
470
460
|
|
|
471
|
-
if (!opts || !
|
|
461
|
+
if (!opts || !hasUserToken) {
|
|
472
462
|
var error = {
|
|
473
463
|
code: "INVALID_INIT",
|
|
474
|
-
message: "requires {
|
|
464
|
+
message: "requires { userToken }",
|
|
475
465
|
};
|
|
476
466
|
logError("init", error.message);
|
|
477
467
|
if (opts && typeof opts.onError === "function") {
|
|
@@ -491,10 +481,6 @@
|
|
|
491
481
|
sessionExpiresAt = 0;
|
|
492
482
|
paymentLink = null;
|
|
493
483
|
|
|
494
|
-
publishableKey = opts.publishableKey;
|
|
495
|
-
userId = opts.userId || null;
|
|
496
|
-
userEmail = opts.userEmail || null;
|
|
497
|
-
userRole = opts.userRole || null;
|
|
498
484
|
userToken = opts.userToken || null;
|
|
499
485
|
appOrigin = opts.origin || null;
|
|
500
486
|
initCallbacks.onReady = opts.onReady || null;
|
|
@@ -823,10 +809,6 @@
|
|
|
823
809
|
clearSessionRequest();
|
|
824
810
|
teardownDialog();
|
|
825
811
|
teardownMount();
|
|
826
|
-
publishableKey = null;
|
|
827
|
-
userId = null;
|
|
828
|
-
userEmail = null;
|
|
829
|
-
userRole = null;
|
|
830
812
|
userToken = null;
|
|
831
813
|
paymentLink = null;
|
|
832
814
|
sessionToken = null;
|