@greensecurity/javascript-sdk 0.43.1-beta.92 → 0.43.1-beta.94
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 +3 -0
- package/dist/commonjs/__tests__/users.test.js +17 -0
- package/dist/commonjs/__tests__/users.test.js.map +1 -1
- package/dist/commonjs/__tests__/webhooks.test.js +1 -1
- package/dist/commonjs/__tests__/webhooks.test.js.map +1 -1
- package/dist/commonjs/funcs/usersSwitchAccount.d.ts +18 -0
- package/dist/commonjs/funcs/usersSwitchAccount.d.ts.map +1 -0
- package/dist/commonjs/funcs/usersSwitchAccount.js +117 -0
- package/dist/commonjs/funcs/usersSwitchAccount.js.map +1 -0
- package/dist/commonjs/lib/config.d.ts +2 -2
- package/dist/commonjs/lib/config.js +2 -2
- package/dist/commonjs/models/operations/index.d.ts +1 -0
- package/dist/commonjs/models/operations/index.d.ts.map +1 -1
- package/dist/commonjs/models/operations/index.js +1 -0
- package/dist/commonjs/models/operations/index.js.map +1 -1
- package/dist/commonjs/models/operations/switchaccount.d.ts +48 -0
- package/dist/commonjs/models/operations/switchaccount.d.ts.map +1 -0
- package/dist/commonjs/models/operations/switchaccount.js +91 -0
- package/dist/commonjs/models/operations/switchaccount.js.map +1 -0
- package/dist/commonjs/react-query/index.d.ts +1 -0
- package/dist/commonjs/react-query/index.d.ts.map +1 -1
- package/dist/commonjs/react-query/index.js +1 -0
- package/dist/commonjs/react-query/index.js.map +1 -1
- package/dist/commonjs/react-query/usersSwitchAccount.d.ts +23 -0
- package/dist/commonjs/react-query/usersSwitchAccount.d.ts.map +1 -0
- package/dist/commonjs/react-query/usersSwitchAccount.js +47 -0
- package/dist/commonjs/react-query/usersSwitchAccount.js.map +1 -0
- package/dist/commonjs/sdk/users.d.ts +7 -0
- package/dist/commonjs/sdk/users.d.ts.map +1 -1
- package/dist/commonjs/sdk/users.js +10 -0
- package/dist/commonjs/sdk/users.js.map +1 -1
- package/dist/esm/__tests__/users.test.js +17 -0
- package/dist/esm/__tests__/users.test.js.map +1 -1
- package/dist/esm/__tests__/webhooks.test.js +1 -1
- package/dist/esm/__tests__/webhooks.test.js.map +1 -1
- package/dist/esm/funcs/usersSwitchAccount.d.ts +18 -0
- package/dist/esm/funcs/usersSwitchAccount.d.ts.map +1 -0
- package/dist/esm/funcs/usersSwitchAccount.js +81 -0
- package/dist/esm/funcs/usersSwitchAccount.js.map +1 -0
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/config.js +2 -2
- package/dist/esm/models/operations/index.d.ts +1 -0
- package/dist/esm/models/operations/index.d.ts.map +1 -1
- package/dist/esm/models/operations/index.js +1 -0
- package/dist/esm/models/operations/index.js.map +1 -1
- package/dist/esm/models/operations/switchaccount.d.ts +48 -0
- package/dist/esm/models/operations/switchaccount.d.ts.map +1 -0
- package/dist/esm/models/operations/switchaccount.js +52 -0
- package/dist/esm/models/operations/switchaccount.js.map +1 -0
- package/dist/esm/react-query/index.d.ts +1 -0
- package/dist/esm/react-query/index.d.ts.map +1 -1
- package/dist/esm/react-query/index.js +1 -0
- package/dist/esm/react-query/index.js.map +1 -1
- package/dist/esm/react-query/usersSwitchAccount.d.ts +23 -0
- package/dist/esm/react-query/usersSwitchAccount.d.ts.map +1 -0
- package/dist/esm/react-query/usersSwitchAccount.js +42 -0
- package/dist/esm/react-query/usersSwitchAccount.js.map +1 -0
- package/dist/esm/sdk/users.d.ts +7 -0
- package/dist/esm/sdk/users.d.ts.map +1 -1
- package/dist/esm/sdk/users.js +10 -0
- package/dist/esm/sdk/users.js.map +1 -1
- package/examples/package-lock.json +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/__tests__/users.test.ts +20 -0
- package/src/__tests__/webhooks.test.ts +1 -1
- package/src/funcs/usersSwitchAccount.ts +168 -0
- package/src/lib/config.ts +2 -2
- package/src/models/operations/index.ts +1 -0
- package/src/models/operations/switchaccount.ts +124 -0
- package/src/react-query/index.ts +1 -0
- package/src/react-query/usersSwitchAccount.ts +89 -0
- package/src/sdk/users.ts +18 -0
package/package.json
CHANGED
|
@@ -71,3 +71,23 @@ test("Users Get Linked Users", async () => {
|
|
|
71
71
|
],
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
|
+
|
|
75
|
+
test("Users Switch Account", async () => {
|
|
76
|
+
const testHttpClient = createTestHTTPClient("switchAccount");
|
|
77
|
+
|
|
78
|
+
const greenSecurity = new GreenSecurity({
|
|
79
|
+
serverURL: process.env["TEST_SERVER_URL"] ?? "https://localhost:3000/api",
|
|
80
|
+
httpClient: testHttpClient,
|
|
81
|
+
security: {
|
|
82
|
+
token: process.env["GREEN_SECURITY_TOKEN"] ?? "value",
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const result = await greenSecurity.users.switchAccount({
|
|
87
|
+
targetUserId: 999867,
|
|
88
|
+
});
|
|
89
|
+
expect(result).toBeDefined();
|
|
90
|
+
expect(result).toEqual({
|
|
91
|
+
userToken: {},
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -20,7 +20,7 @@ test("Webhooks List All Webhook Endpoints", async () => {
|
|
|
20
20
|
const testWebhookListForVendorUserResult = await greenSecurity.webhooks
|
|
21
21
|
.listAllWebhookEndpoints({
|
|
22
22
|
itemsPerPage: 25,
|
|
23
|
-
desc:
|
|
23
|
+
desc: true,
|
|
24
24
|
sort: "",
|
|
25
25
|
});
|
|
26
26
|
expect(testWebhookListForVendorUserResult).toBeDefined();
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { GreenSecurityCore } from "../core.js";
|
|
6
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
7
|
+
import * as M from "../lib/matchers.js";
|
|
8
|
+
import { compactMap } from "../lib/primitives.js";
|
|
9
|
+
import { safeParse } from "../lib/schemas.js";
|
|
10
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
11
|
+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
12
|
+
import { pathToFunc } from "../lib/url.js";
|
|
13
|
+
import { GreenSecurityError } from "../models/errors/greensecurityerror.js";
|
|
14
|
+
import {
|
|
15
|
+
ConnectionError,
|
|
16
|
+
InvalidRequestError,
|
|
17
|
+
RequestAbortedError,
|
|
18
|
+
RequestTimeoutError,
|
|
19
|
+
UnexpectedClientError,
|
|
20
|
+
} from "../models/errors/httpclienterrors.js";
|
|
21
|
+
import * as errors from "../models/errors/index.js";
|
|
22
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
23
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
24
|
+
import * as operations from "../models/operations/index.js";
|
|
25
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
26
|
+
import { Result } from "../types/fp.js";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Switch to linked account
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* If a user has two different types of accounts (i.e. Company Manager and Vendor) this endpoint allows the integration to swap the token from the existing user to the linked account user. For API integrations, the `source_user_id` field is required and must be the ID of the user whose session will be switched into the target user's token.
|
|
33
|
+
*/
|
|
34
|
+
export function usersSwitchAccount(
|
|
35
|
+
client: GreenSecurityCore,
|
|
36
|
+
request: operations.SwitchAccountRequestBody,
|
|
37
|
+
options?: RequestOptions,
|
|
38
|
+
): APIPromise<
|
|
39
|
+
Result<
|
|
40
|
+
operations.SwitchAccountResponseBody,
|
|
41
|
+
| errors.ApiErrorResponse
|
|
42
|
+
| GreenSecurityError
|
|
43
|
+
| ResponseValidationError
|
|
44
|
+
| ConnectionError
|
|
45
|
+
| RequestAbortedError
|
|
46
|
+
| RequestTimeoutError
|
|
47
|
+
| InvalidRequestError
|
|
48
|
+
| UnexpectedClientError
|
|
49
|
+
| SDKValidationError
|
|
50
|
+
>
|
|
51
|
+
> {
|
|
52
|
+
return new APIPromise($do(
|
|
53
|
+
client,
|
|
54
|
+
request,
|
|
55
|
+
options,
|
|
56
|
+
));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function $do(
|
|
60
|
+
client: GreenSecurityCore,
|
|
61
|
+
request: operations.SwitchAccountRequestBody,
|
|
62
|
+
options?: RequestOptions,
|
|
63
|
+
): Promise<
|
|
64
|
+
[
|
|
65
|
+
Result<
|
|
66
|
+
operations.SwitchAccountResponseBody,
|
|
67
|
+
| errors.ApiErrorResponse
|
|
68
|
+
| GreenSecurityError
|
|
69
|
+
| ResponseValidationError
|
|
70
|
+
| ConnectionError
|
|
71
|
+
| RequestAbortedError
|
|
72
|
+
| RequestTimeoutError
|
|
73
|
+
| InvalidRequestError
|
|
74
|
+
| UnexpectedClientError
|
|
75
|
+
| SDKValidationError
|
|
76
|
+
>,
|
|
77
|
+
APICall,
|
|
78
|
+
]
|
|
79
|
+
> {
|
|
80
|
+
const parsed = safeParse(
|
|
81
|
+
request,
|
|
82
|
+
(value) => operations.SwitchAccountRequestBody$outboundSchema.parse(value),
|
|
83
|
+
"Input validation failed",
|
|
84
|
+
);
|
|
85
|
+
if (!parsed.ok) {
|
|
86
|
+
return [parsed, { status: "invalid" }];
|
|
87
|
+
}
|
|
88
|
+
const payload = parsed.value;
|
|
89
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
90
|
+
|
|
91
|
+
const path = pathToFunc("/users/switch-account")();
|
|
92
|
+
|
|
93
|
+
const headers = new Headers(compactMap({
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
Accept: "application/json",
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
const securityInput = await extractSecurity(client._options.security);
|
|
99
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
100
|
+
|
|
101
|
+
const context = {
|
|
102
|
+
options: client._options,
|
|
103
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
104
|
+
operationID: "switchAccount",
|
|
105
|
+
oAuth2Scopes: null,
|
|
106
|
+
|
|
107
|
+
resolvedSecurity: requestSecurity,
|
|
108
|
+
|
|
109
|
+
securitySource: client._options.security,
|
|
110
|
+
retryConfig: options?.retries
|
|
111
|
+
|| client._options.retryConfig
|
|
112
|
+
|| { strategy: "none" },
|
|
113
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const requestRes = client._createRequest(context, {
|
|
117
|
+
security: requestSecurity,
|
|
118
|
+
method: "POST",
|
|
119
|
+
baseURL: options?.serverURL,
|
|
120
|
+
path: path,
|
|
121
|
+
headers: headers,
|
|
122
|
+
body: body,
|
|
123
|
+
userAgent: client._options.userAgent,
|
|
124
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
125
|
+
}, options);
|
|
126
|
+
if (!requestRes.ok) {
|
|
127
|
+
return [requestRes, { status: "invalid" }];
|
|
128
|
+
}
|
|
129
|
+
const req = requestRes.value;
|
|
130
|
+
|
|
131
|
+
const doResult = await client._do(req, {
|
|
132
|
+
context,
|
|
133
|
+
errorCodes: ["400", "401", "403", "404", "422", "4XX", "500", "5XX"],
|
|
134
|
+
retryConfig: context.retryConfig,
|
|
135
|
+
retryCodes: context.retryCodes,
|
|
136
|
+
});
|
|
137
|
+
if (!doResult.ok) {
|
|
138
|
+
return [doResult, { status: "request-error", request: req }];
|
|
139
|
+
}
|
|
140
|
+
const response = doResult.value;
|
|
141
|
+
|
|
142
|
+
const responseFields = {
|
|
143
|
+
HttpMeta: { Response: response, Request: req },
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const [result] = await M.match<
|
|
147
|
+
operations.SwitchAccountResponseBody,
|
|
148
|
+
| errors.ApiErrorResponse
|
|
149
|
+
| GreenSecurityError
|
|
150
|
+
| ResponseValidationError
|
|
151
|
+
| ConnectionError
|
|
152
|
+
| RequestAbortedError
|
|
153
|
+
| RequestTimeoutError
|
|
154
|
+
| InvalidRequestError
|
|
155
|
+
| UnexpectedClientError
|
|
156
|
+
| SDKValidationError
|
|
157
|
+
>(
|
|
158
|
+
M.json(200, operations.SwitchAccountResponseBody$inboundSchema),
|
|
159
|
+
M.jsonErr([400, 401, 403, 404, 422], errors.ApiErrorResponse$inboundSchema),
|
|
160
|
+
M.fail("4XX"),
|
|
161
|
+
M.fail([500, "5XX"]),
|
|
162
|
+
)(response, req, { extraFields: responseFields });
|
|
163
|
+
if (!result.ok) {
|
|
164
|
+
return [result, { status: "complete", request: req, response }];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return [result, { status: "complete", request: req, response }];
|
|
168
|
+
}
|
package/src/lib/config.ts
CHANGED
|
@@ -80,8 +80,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
80
80
|
export const SDK_METADATA = {
|
|
81
81
|
language: "typescript",
|
|
82
82
|
openapiDocVersion: "0.0.11",
|
|
83
|
-
sdkVersion: "0.43.1-beta.
|
|
83
|
+
sdkVersion: "0.43.1-beta.92",
|
|
84
84
|
genVersion: "2.794.1",
|
|
85
85
|
userAgent:
|
|
86
|
-
"speakeasy-sdk/typescript 0.43.1-beta.
|
|
86
|
+
"speakeasy-sdk/typescript 0.43.1-beta.92 2.794.1 0.0.11 @greensecurity/javascript-sdk",
|
|
87
87
|
} as const;
|
|
@@ -86,6 +86,7 @@ export * from "./securityzonecheckin.js";
|
|
|
86
86
|
export * from "./senddownloadcode.js";
|
|
87
87
|
export * from "./submitscreeningresponse.js";
|
|
88
88
|
export * from "./submitvendorcredential.js";
|
|
89
|
+
export * from "./switchaccount.js";
|
|
89
90
|
export * from "./updatedatarequest.js";
|
|
90
91
|
export * from "./updateevent.js";
|
|
91
92
|
export * from "./updatefhirconfigbyid.js";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v3";
|
|
6
|
+
import { remap as remap$ } from "../../lib/primitives.js";
|
|
7
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
8
|
+
import { ClosedEnum } from "../../types/enums.js";
|
|
9
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
10
|
+
import * as types from "../../types/primitives.js";
|
|
11
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
12
|
+
|
|
13
|
+
export type SwitchAccountRequestBody = {
|
|
14
|
+
/**
|
|
15
|
+
* ID of the linked user to switch to
|
|
16
|
+
*/
|
|
17
|
+
targetUserId: number;
|
|
18
|
+
/**
|
|
19
|
+
* Required for API integrations. The ID of the user whose session will be switched. The API user must have an app activation for this user.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
*/
|
|
23
|
+
sourceUserId?: number | undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const TokenType = {
|
|
27
|
+
Permanent: "permanent",
|
|
28
|
+
} as const;
|
|
29
|
+
export type TokenType = ClosedEnum<typeof TokenType>;
|
|
30
|
+
|
|
31
|
+
export type UserToken = {
|
|
32
|
+
token?: string | undefined;
|
|
33
|
+
tokenType?: TokenType | undefined;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Successfully switched. Use the returned token with GET /users/:id to fetch full user data.
|
|
38
|
+
*/
|
|
39
|
+
export type SwitchAccountResponseBody = {
|
|
40
|
+
userToken: UserToken;
|
|
41
|
+
userId?: number | undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
export type SwitchAccountRequestBody$Outbound = {
|
|
46
|
+
target_user_id: number;
|
|
47
|
+
source_user_id?: number | undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** @internal */
|
|
51
|
+
export const SwitchAccountRequestBody$outboundSchema: z.ZodType<
|
|
52
|
+
SwitchAccountRequestBody$Outbound,
|
|
53
|
+
z.ZodTypeDef,
|
|
54
|
+
SwitchAccountRequestBody
|
|
55
|
+
> = z.object({
|
|
56
|
+
targetUserId: z.number().int(),
|
|
57
|
+
sourceUserId: z.number().int().optional(),
|
|
58
|
+
}).transform((v) => {
|
|
59
|
+
return remap$(v, {
|
|
60
|
+
targetUserId: "target_user_id",
|
|
61
|
+
sourceUserId: "source_user_id",
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export function switchAccountRequestBodyToJSON(
|
|
66
|
+
switchAccountRequestBody: SwitchAccountRequestBody,
|
|
67
|
+
): string {
|
|
68
|
+
return JSON.stringify(
|
|
69
|
+
SwitchAccountRequestBody$outboundSchema.parse(switchAccountRequestBody),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** @internal */
|
|
74
|
+
export const TokenType$inboundSchema: z.ZodNativeEnum<typeof TokenType> = z
|
|
75
|
+
.nativeEnum(TokenType);
|
|
76
|
+
|
|
77
|
+
/** @internal */
|
|
78
|
+
export const UserToken$inboundSchema: z.ZodType<
|
|
79
|
+
UserToken,
|
|
80
|
+
z.ZodTypeDef,
|
|
81
|
+
unknown
|
|
82
|
+
> = z.object({
|
|
83
|
+
token: types.optional(types.string()),
|
|
84
|
+
token_type: types.optional(TokenType$inboundSchema),
|
|
85
|
+
}).transform((v) => {
|
|
86
|
+
return remap$(v, {
|
|
87
|
+
"token_type": "tokenType",
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export function userTokenFromJSON(
|
|
92
|
+
jsonString: string,
|
|
93
|
+
): SafeParseResult<UserToken, SDKValidationError> {
|
|
94
|
+
return safeParse(
|
|
95
|
+
jsonString,
|
|
96
|
+
(x) => UserToken$inboundSchema.parse(JSON.parse(x)),
|
|
97
|
+
`Failed to parse 'UserToken' from JSON`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @internal */
|
|
102
|
+
export const SwitchAccountResponseBody$inboundSchema: z.ZodType<
|
|
103
|
+
SwitchAccountResponseBody,
|
|
104
|
+
z.ZodTypeDef,
|
|
105
|
+
unknown
|
|
106
|
+
> = z.object({
|
|
107
|
+
user_token: z.lazy(() => UserToken$inboundSchema),
|
|
108
|
+
user_id: types.optional(types.number()),
|
|
109
|
+
}).transform((v) => {
|
|
110
|
+
return remap$(v, {
|
|
111
|
+
"user_token": "userToken",
|
|
112
|
+
"user_id": "userId",
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export function switchAccountResponseBodyFromJSON(
|
|
117
|
+
jsonString: string,
|
|
118
|
+
): SafeParseResult<SwitchAccountResponseBody, SDKValidationError> {
|
|
119
|
+
return safeParse(
|
|
120
|
+
jsonString,
|
|
121
|
+
(x) => SwitchAccountResponseBody$inboundSchema.parse(JSON.parse(x)),
|
|
122
|
+
`Failed to parse 'SwitchAccountResponseBody' from JSON`,
|
|
123
|
+
);
|
|
124
|
+
}
|
package/src/react-query/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ export * from "./usersPassword.js";
|
|
|
50
50
|
export * from "./usersPasswordResetRequest.js";
|
|
51
51
|
export * from "./usersPostAuthenticate.js";
|
|
52
52
|
export * from "./usersRotateApiKey.js";
|
|
53
|
+
export * from "./usersSwitchAccount.js";
|
|
53
54
|
export * from "./vendorsAcceptVendorCredential.js";
|
|
54
55
|
export * from "./vendorsAddVendorCredentialFile.js";
|
|
55
56
|
export * from "./vendorsAddVendorManagedByCompany.js";
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
MutationKey,
|
|
7
|
+
useMutation,
|
|
8
|
+
UseMutationResult,
|
|
9
|
+
} from "@tanstack/react-query";
|
|
10
|
+
import { GreenSecurityCore } from "../core.js";
|
|
11
|
+
import { usersSwitchAccount } from "../funcs/usersSwitchAccount.js";
|
|
12
|
+
import { combineSignals } from "../lib/primitives.js";
|
|
13
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
14
|
+
import * as operations from "../models/operations/index.js";
|
|
15
|
+
import { unwrapAsync } from "../types/fp.js";
|
|
16
|
+
import { useGreenSecurityContext } from "./_context.js";
|
|
17
|
+
import { MutationHookOptions } from "./_types.js";
|
|
18
|
+
|
|
19
|
+
export type UsersSwitchAccountMutationVariables = {
|
|
20
|
+
request: operations.SwitchAccountRequestBody;
|
|
21
|
+
options?: RequestOptions;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type UsersSwitchAccountMutationData =
|
|
25
|
+
operations.SwitchAccountResponseBody;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Switch to linked account
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* If a user has two different types of accounts (i.e. Company Manager and Vendor) this endpoint allows the integration to swap the token from the existing user to the linked account user. For API integrations, the `source_user_id` field is required and must be the ID of the user whose session will be switched into the target user's token.
|
|
32
|
+
*/
|
|
33
|
+
export function useUsersSwitchAccountMutation(
|
|
34
|
+
options?: MutationHookOptions<
|
|
35
|
+
UsersSwitchAccountMutationData,
|
|
36
|
+
Error,
|
|
37
|
+
UsersSwitchAccountMutationVariables
|
|
38
|
+
>,
|
|
39
|
+
): UseMutationResult<
|
|
40
|
+
UsersSwitchAccountMutationData,
|
|
41
|
+
Error,
|
|
42
|
+
UsersSwitchAccountMutationVariables
|
|
43
|
+
> {
|
|
44
|
+
const client = useGreenSecurityContext();
|
|
45
|
+
return useMutation({
|
|
46
|
+
...buildUsersSwitchAccountMutation(client, options),
|
|
47
|
+
...options,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function mutationKeyUsersSwitchAccount(): MutationKey {
|
|
52
|
+
return ["@greensecurity/javascript-sdk", "users", "switchAccount"];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function buildUsersSwitchAccountMutation(
|
|
56
|
+
client$: GreenSecurityCore,
|
|
57
|
+
hookOptions?: RequestOptions,
|
|
58
|
+
): {
|
|
59
|
+
mutationKey: MutationKey;
|
|
60
|
+
mutationFn: (
|
|
61
|
+
variables: UsersSwitchAccountMutationVariables,
|
|
62
|
+
) => Promise<UsersSwitchAccountMutationData>;
|
|
63
|
+
} {
|
|
64
|
+
return {
|
|
65
|
+
mutationKey: mutationKeyUsersSwitchAccount(),
|
|
66
|
+
mutationFn: function usersSwitchAccountMutationFn({
|
|
67
|
+
request,
|
|
68
|
+
options,
|
|
69
|
+
}): Promise<UsersSwitchAccountMutationData> {
|
|
70
|
+
const mergedOptions = {
|
|
71
|
+
...hookOptions,
|
|
72
|
+
...options,
|
|
73
|
+
fetchOptions: {
|
|
74
|
+
...hookOptions?.fetchOptions,
|
|
75
|
+
...options?.fetchOptions,
|
|
76
|
+
signal: combineSignals(
|
|
77
|
+
hookOptions?.fetchOptions?.signal,
|
|
78
|
+
options?.fetchOptions?.signal,
|
|
79
|
+
),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return unwrapAsync(usersSwitchAccount(
|
|
83
|
+
client$,
|
|
84
|
+
request,
|
|
85
|
+
mergedOptions,
|
|
86
|
+
));
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
package/src/sdk/users.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { usersPassword } from "../funcs/usersPassword.js";
|
|
|
11
11
|
import { usersPasswordResetRequest } from "../funcs/usersPasswordResetRequest.js";
|
|
12
12
|
import { usersPostAuthenticate } from "../funcs/usersPostAuthenticate.js";
|
|
13
13
|
import { usersRotateApiKey } from "../funcs/usersRotateApiKey.js";
|
|
14
|
+
import { usersSwitchAccount } from "../funcs/usersSwitchAccount.js";
|
|
14
15
|
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
|
|
15
16
|
import * as components from "../models/components/index.js";
|
|
16
17
|
import * as operations from "../models/operations/index.js";
|
|
@@ -133,6 +134,23 @@ export class Users extends ClientSDK {
|
|
|
133
134
|
));
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Switch to linked account
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* If a user has two different types of accounts (i.e. Company Manager and Vendor) this endpoint allows the integration to swap the token from the existing user to the linked account user. For API integrations, the `source_user_id` field is required and must be the ID of the user whose session will be switched into the target user's token.
|
|
142
|
+
*/
|
|
143
|
+
async switchAccount(
|
|
144
|
+
request: operations.SwitchAccountRequestBody,
|
|
145
|
+
options?: RequestOptions,
|
|
146
|
+
): Promise<operations.SwitchAccountResponseBody> {
|
|
147
|
+
return unwrapAsync(usersSwitchAccount(
|
|
148
|
+
this,
|
|
149
|
+
request,
|
|
150
|
+
options,
|
|
151
|
+
));
|
|
152
|
+
}
|
|
153
|
+
|
|
136
154
|
/**
|
|
137
155
|
* Magic link
|
|
138
156
|
*
|