@greensecurity/javascript-sdk 0.45.0-beta.16 → 0.45.0-beta.17

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.
Files changed (139) hide show
  1. package/dist/commonjs/__tests__/vendors.test.js +1 -1
  2. package/dist/commonjs/__tests__/vendors.test.js.map +1 -1
  3. package/dist/commonjs/__tests__/webhooks.test.js +1 -1
  4. package/dist/commonjs/__tests__/webhooks.test.js.map +1 -1
  5. package/dist/commonjs/__tests__/zones.test.js +2 -9
  6. package/dist/commonjs/__tests__/zones.test.js.map +1 -1
  7. package/dist/commonjs/funcs/usersPostAuthenticate.d.ts +37 -0
  8. package/dist/commonjs/funcs/usersPostAuthenticate.d.ts.map +1 -1
  9. package/dist/commonjs/funcs/usersPostAuthenticate.js +37 -0
  10. package/dist/commonjs/funcs/usersPostAuthenticate.js.map +1 -1
  11. package/dist/commonjs/lib/config.d.ts +2 -2
  12. package/dist/commonjs/lib/config.js +2 -2
  13. package/dist/commonjs/models/components/authenticatesuccessresponse.d.ts +91 -0
  14. package/dist/commonjs/models/components/authenticatesuccessresponse.d.ts.map +1 -0
  15. package/dist/commonjs/models/components/authenticatesuccessresponse.js +100 -0
  16. package/dist/commonjs/models/components/authenticatesuccessresponse.js.map +1 -0
  17. package/dist/commonjs/models/components/index.d.ts +2 -0
  18. package/dist/commonjs/models/components/index.d.ts.map +1 -1
  19. package/dist/commonjs/models/components/index.js +2 -0
  20. package/dist/commonjs/models/components/index.js.map +1 -1
  21. package/dist/commonjs/models/components/loginemailandpassword.d.ts +34 -0
  22. package/dist/commonjs/models/components/loginemailandpassword.d.ts.map +1 -1
  23. package/dist/commonjs/models/components/loginemailandpassword.js +2 -0
  24. package/dist/commonjs/models/components/loginemailandpassword.js.map +1 -1
  25. package/dist/commonjs/models/components/loginrequirementsfromemail.d.ts +34 -0
  26. package/dist/commonjs/models/components/loginrequirementsfromemail.d.ts.map +1 -1
  27. package/dist/commonjs/models/components/loginrequirementsfromemail.js +2 -0
  28. package/dist/commonjs/models/components/loginrequirementsfromemail.js.map +1 -1
  29. package/dist/commonjs/models/components/mfarequiredresponse.d.ts +33 -0
  30. package/dist/commonjs/models/components/mfarequiredresponse.d.ts.map +1 -1
  31. package/dist/commonjs/models/components/mfarequiredresponse.js +2 -0
  32. package/dist/commonjs/models/components/mfarequiredresponse.js.map +1 -1
  33. package/dist/commonjs/models/components/passwordnotsetresponse.d.ts +34 -1
  34. package/dist/commonjs/models/components/passwordnotsetresponse.d.ts.map +1 -1
  35. package/dist/commonjs/models/components/passwordnotsetresponse.js +2 -0
  36. package/dist/commonjs/models/components/passwordnotsetresponse.js.map +1 -1
  37. package/dist/commonjs/models/components/passwordrequiredresponse.d.ts +33 -0
  38. package/dist/commonjs/models/components/passwordrequiredresponse.d.ts.map +1 -1
  39. package/dist/commonjs/models/components/passwordrequiredresponse.js +6 -0
  40. package/dist/commonjs/models/components/passwordrequiredresponse.js.map +1 -1
  41. package/dist/commonjs/models/components/samlloginrequiredresponse.d.ts +33 -0
  42. package/dist/commonjs/models/components/samlloginrequiredresponse.d.ts.map +1 -1
  43. package/dist/commonjs/models/components/samlloginrequiredresponse.js +2 -0
  44. package/dist/commonjs/models/components/samlloginrequiredresponse.js.map +1 -1
  45. package/dist/commonjs/models/components/ssocontinuation.d.ts +44 -0
  46. package/dist/commonjs/models/components/ssocontinuation.d.ts.map +1 -0
  47. package/dist/commonjs/models/components/ssocontinuation.js +56 -0
  48. package/dist/commonjs/models/components/ssocontinuation.js.map +1 -0
  49. package/dist/commonjs/models/operations/postauthenticate.d.ts +1 -1
  50. package/dist/commonjs/models/operations/postauthenticate.d.ts.map +1 -1
  51. package/dist/commonjs/models/operations/postauthenticate.js +1 -1
  52. package/dist/commonjs/models/operations/postauthenticate.js.map +1 -1
  53. package/dist/commonjs/react-query/usersPostAuthenticate.d.ts +37 -0
  54. package/dist/commonjs/react-query/usersPostAuthenticate.d.ts.map +1 -1
  55. package/dist/commonjs/react-query/usersPostAuthenticate.js +37 -0
  56. package/dist/commonjs/react-query/usersPostAuthenticate.js.map +1 -1
  57. package/dist/commonjs/sdk/users.d.ts +37 -0
  58. package/dist/commonjs/sdk/users.d.ts.map +1 -1
  59. package/dist/commonjs/sdk/users.js +37 -0
  60. package/dist/commonjs/sdk/users.js.map +1 -1
  61. package/dist/esm/__tests__/vendors.test.js +1 -1
  62. package/dist/esm/__tests__/vendors.test.js.map +1 -1
  63. package/dist/esm/__tests__/webhooks.test.js +1 -1
  64. package/dist/esm/__tests__/webhooks.test.js.map +1 -1
  65. package/dist/esm/__tests__/zones.test.js +2 -9
  66. package/dist/esm/__tests__/zones.test.js.map +1 -1
  67. package/dist/esm/funcs/usersPostAuthenticate.d.ts +37 -0
  68. package/dist/esm/funcs/usersPostAuthenticate.d.ts.map +1 -1
  69. package/dist/esm/funcs/usersPostAuthenticate.js +37 -0
  70. package/dist/esm/funcs/usersPostAuthenticate.js.map +1 -1
  71. package/dist/esm/lib/config.d.ts +2 -2
  72. package/dist/esm/lib/config.js +2 -2
  73. package/dist/esm/models/components/authenticatesuccessresponse.d.ts +91 -0
  74. package/dist/esm/models/components/authenticatesuccessresponse.d.ts.map +1 -0
  75. package/dist/esm/models/components/authenticatesuccessresponse.js +61 -0
  76. package/dist/esm/models/components/authenticatesuccessresponse.js.map +1 -0
  77. package/dist/esm/models/components/index.d.ts +2 -0
  78. package/dist/esm/models/components/index.d.ts.map +1 -1
  79. package/dist/esm/models/components/index.js +2 -0
  80. package/dist/esm/models/components/index.js.map +1 -1
  81. package/dist/esm/models/components/loginemailandpassword.d.ts +34 -0
  82. package/dist/esm/models/components/loginemailandpassword.d.ts.map +1 -1
  83. package/dist/esm/models/components/loginemailandpassword.js +2 -0
  84. package/dist/esm/models/components/loginemailandpassword.js.map +1 -1
  85. package/dist/esm/models/components/loginrequirementsfromemail.d.ts +34 -0
  86. package/dist/esm/models/components/loginrequirementsfromemail.d.ts.map +1 -1
  87. package/dist/esm/models/components/loginrequirementsfromemail.js +2 -0
  88. package/dist/esm/models/components/loginrequirementsfromemail.js.map +1 -1
  89. package/dist/esm/models/components/mfarequiredresponse.d.ts +33 -0
  90. package/dist/esm/models/components/mfarequiredresponse.d.ts.map +1 -1
  91. package/dist/esm/models/components/mfarequiredresponse.js +2 -0
  92. package/dist/esm/models/components/mfarequiredresponse.js.map +1 -1
  93. package/dist/esm/models/components/passwordnotsetresponse.d.ts +34 -1
  94. package/dist/esm/models/components/passwordnotsetresponse.d.ts.map +1 -1
  95. package/dist/esm/models/components/passwordnotsetresponse.js +2 -0
  96. package/dist/esm/models/components/passwordnotsetresponse.js.map +1 -1
  97. package/dist/esm/models/components/passwordrequiredresponse.d.ts +33 -0
  98. package/dist/esm/models/components/passwordrequiredresponse.d.ts.map +1 -1
  99. package/dist/esm/models/components/passwordrequiredresponse.js +6 -0
  100. package/dist/esm/models/components/passwordrequiredresponse.js.map +1 -1
  101. package/dist/esm/models/components/samlloginrequiredresponse.d.ts +33 -0
  102. package/dist/esm/models/components/samlloginrequiredresponse.d.ts.map +1 -1
  103. package/dist/esm/models/components/samlloginrequiredresponse.js +2 -0
  104. package/dist/esm/models/components/samlloginrequiredresponse.js.map +1 -1
  105. package/dist/esm/models/components/ssocontinuation.d.ts +44 -0
  106. package/dist/esm/models/components/ssocontinuation.d.ts.map +1 -0
  107. package/dist/esm/models/components/ssocontinuation.js +19 -0
  108. package/dist/esm/models/components/ssocontinuation.js.map +1 -0
  109. package/dist/esm/models/operations/postauthenticate.d.ts +1 -1
  110. package/dist/esm/models/operations/postauthenticate.d.ts.map +1 -1
  111. package/dist/esm/models/operations/postauthenticate.js +1 -1
  112. package/dist/esm/models/operations/postauthenticate.js.map +1 -1
  113. package/dist/esm/react-query/usersPostAuthenticate.d.ts +37 -0
  114. package/dist/esm/react-query/usersPostAuthenticate.d.ts.map +1 -1
  115. package/dist/esm/react-query/usersPostAuthenticate.js +37 -0
  116. package/dist/esm/react-query/usersPostAuthenticate.js.map +1 -1
  117. package/dist/esm/sdk/users.d.ts +37 -0
  118. package/dist/esm/sdk/users.d.ts.map +1 -1
  119. package/dist/esm/sdk/users.js +37 -0
  120. package/dist/esm/sdk/users.js.map +1 -1
  121. package/jsr.json +1 -1
  122. package/package.json +1 -1
  123. package/src/__tests__/vendors.test.ts +1 -1
  124. package/src/__tests__/webhooks.test.ts +1 -1
  125. package/src/__tests__/zones.test.ts +2 -9
  126. package/src/funcs/usersPostAuthenticate.ts +37 -0
  127. package/src/lib/config.ts +2 -2
  128. package/src/models/components/authenticatesuccessresponse.ts +189 -0
  129. package/src/models/components/index.ts +2 -0
  130. package/src/models/components/loginemailandpassword.ts +36 -0
  131. package/src/models/components/loginrequirementsfromemail.ts +36 -0
  132. package/src/models/components/mfarequiredresponse.ts +35 -0
  133. package/src/models/components/passwordnotsetresponse.ts +36 -1
  134. package/src/models/components/passwordrequiredresponse.ts +39 -0
  135. package/src/models/components/samlloginrequiredresponse.ts +35 -0
  136. package/src/models/components/ssocontinuation.ts +71 -0
  137. package/src/models/operations/postauthenticate.ts +2 -2
  138. package/src/react-query/usersPostAuthenticate.ts +37 -0
  139. package/src/sdk/users.ts +37 -0
@@ -0,0 +1,189 @@
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 * as openEnums from "../../types/enums.js";
9
+ import { OpenEnum } from "../../types/enums.js";
10
+ import { Result as SafeParseResult } from "../../types/fp.js";
11
+ import * as types from "../../types/primitives.js";
12
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
13
+ import { Company, Company$inboundSchema } from "./company.js";
14
+ import { Contact, Contact$inboundSchema } from "./contact.js";
15
+ import {
16
+ SsoContinuation,
17
+ SsoContinuation$inboundSchema,
18
+ } from "./ssocontinuation.js";
19
+ import { UserDetails, UserDetails$inboundSchema } from "./userdetails.js";
20
+ import { Vendor, Vendor$inboundSchema } from "./vendor.js";
21
+
22
+ /**
23
+ * A `permanent` user token can be used to access any API endpoint as the logged in user. A `one time` token is used to authenticate the user once.
24
+ */
25
+ export const AuthenticateSuccessResponseTokenType = {
26
+ Permanent: "permanent",
27
+ OneTime: "one time",
28
+ } as const;
29
+ /**
30
+ * A `permanent` user token can be used to access any API endpoint as the logged in user. A `one time` token is used to authenticate the user once.
31
+ */
32
+ export type AuthenticateSuccessResponseTokenType = OpenEnum<
33
+ typeof AuthenticateSuccessResponseTokenType
34
+ >;
35
+
36
+ export type AuthenticateSuccessResponseUserToken = {
37
+ /**
38
+ * This token can be passed in authorization headers for this user.
39
+ */
40
+ token: string;
41
+ /**
42
+ * A `permanent` user token can be used to access any API endpoint as the logged in user. A `one time` token is used to authenticate the user once.
43
+ */
44
+ tokenType: AuthenticateSuccessResponseTokenType;
45
+ };
46
+
47
+ export type AuthenticateSuccessResponseInventoryManager = {};
48
+
49
+ /**
50
+ * A completed login. Identical to the `User` object returned everywhere
51
+ *
52
+ * @remarks
53
+ * else, plus an `sso` object when the request carried a valid `sso_state`
54
+ * and the login therefore has a SAML flow waiting to be finished.
55
+ */
56
+ export type AuthenticateSuccessResponse = {
57
+ /**
58
+ * A `gatekeeper` is a special type of service user. This type of service user is assigned to Kiosks and Apps to verify Vendors using APIs that have some access to facility data.
59
+ */
60
+ isGatekeeper?: boolean | undefined;
61
+ success: boolean;
62
+ /**
63
+ * Core user profile fields returned by user detail and update endpoints.
64
+ */
65
+ user: UserDetails;
66
+ userToken: AuthenticateSuccessResponseUserToken;
67
+ /**
68
+ * Vendor details
69
+ */
70
+ vendor?: Vendor | undefined;
71
+ inventoryManager?: AuthenticateSuccessResponseInventoryManager | undefined;
72
+ /**
73
+ * This object represents a contact at the system or facility level. Use it to verify vendors, create appointments, or check in visitors.
74
+ */
75
+ contact?: Contact | null | undefined;
76
+ /**
77
+ * A simplified representation of a Company, typically used in list views.
78
+ */
79
+ company?: Company | null | undefined;
80
+ /**
81
+ * Where to send the browser to finish a "Login with Green Security" flow.
82
+ *
83
+ * @remarks
84
+ *
85
+ * Present on a `200` from `POST /users/authenticate` only when the request
86
+ * carried a valid, unexpired `sso_state`. Its absence means the login
87
+ * succeeded but the SAML flow did not resume — treat the login as an
88
+ * ordinary one rather than retrying.
89
+ *
90
+ * This object is additive. The login itself is unaffected by it: the
91
+ * caller's own permanent token is in `user_token` exactly as it would be on
92
+ * any other successful authentication, and it is not the token embedded in
93
+ * `continue_url`.
94
+ */
95
+ sso?: SsoContinuation | undefined;
96
+ };
97
+
98
+ /** @internal */
99
+ export const AuthenticateSuccessResponseTokenType$inboundSchema: z.ZodType<
100
+ AuthenticateSuccessResponseTokenType,
101
+ z.ZodTypeDef,
102
+ unknown
103
+ > = openEnums.inboundSchema(AuthenticateSuccessResponseTokenType);
104
+
105
+ /** @internal */
106
+ export const AuthenticateSuccessResponseUserToken$inboundSchema: z.ZodType<
107
+ AuthenticateSuccessResponseUserToken,
108
+ z.ZodTypeDef,
109
+ unknown
110
+ > = z.object({
111
+ token: types.string(),
112
+ token_type: AuthenticateSuccessResponseTokenType$inboundSchema.default(
113
+ "permanent",
114
+ ),
115
+ }).transform((v) => {
116
+ return remap$(v, {
117
+ "token_type": "tokenType",
118
+ });
119
+ });
120
+
121
+ export function authenticateSuccessResponseUserTokenFromJSON(
122
+ jsonString: string,
123
+ ): SafeParseResult<AuthenticateSuccessResponseUserToken, SDKValidationError> {
124
+ return safeParse(
125
+ jsonString,
126
+ (x) =>
127
+ AuthenticateSuccessResponseUserToken$inboundSchema.parse(JSON.parse(x)),
128
+ `Failed to parse 'AuthenticateSuccessResponseUserToken' from JSON`,
129
+ );
130
+ }
131
+
132
+ /** @internal */
133
+ export const AuthenticateSuccessResponseInventoryManager$inboundSchema:
134
+ z.ZodType<
135
+ AuthenticateSuccessResponseInventoryManager,
136
+ z.ZodTypeDef,
137
+ unknown
138
+ > = z.object({});
139
+
140
+ export function authenticateSuccessResponseInventoryManagerFromJSON(
141
+ jsonString: string,
142
+ ): SafeParseResult<
143
+ AuthenticateSuccessResponseInventoryManager,
144
+ SDKValidationError
145
+ > {
146
+ return safeParse(
147
+ jsonString,
148
+ (x) =>
149
+ AuthenticateSuccessResponseInventoryManager$inboundSchema.parse(
150
+ JSON.parse(x),
151
+ ),
152
+ `Failed to parse 'AuthenticateSuccessResponseInventoryManager' from JSON`,
153
+ );
154
+ }
155
+
156
+ /** @internal */
157
+ export const AuthenticateSuccessResponse$inboundSchema: z.ZodType<
158
+ AuthenticateSuccessResponse,
159
+ z.ZodTypeDef,
160
+ unknown
161
+ > = z.object({
162
+ is_gatekeeper: types.optional(types.boolean()),
163
+ success: types.boolean(),
164
+ user: UserDetails$inboundSchema,
165
+ user_token: z.lazy(() => AuthenticateSuccessResponseUserToken$inboundSchema),
166
+ vendor: types.optional(Vendor$inboundSchema),
167
+ inventory_manager: types.optional(
168
+ z.lazy(() => AuthenticateSuccessResponseInventoryManager$inboundSchema),
169
+ ),
170
+ contact: z.nullable(Contact$inboundSchema).optional(),
171
+ company: z.nullable(Company$inboundSchema).optional(),
172
+ sso: types.optional(SsoContinuation$inboundSchema),
173
+ }).transform((v) => {
174
+ return remap$(v, {
175
+ "is_gatekeeper": "isGatekeeper",
176
+ "user_token": "userToken",
177
+ "inventory_manager": "inventoryManager",
178
+ });
179
+ });
180
+
181
+ export function authenticateSuccessResponseFromJSON(
182
+ jsonString: string,
183
+ ): SafeParseResult<AuthenticateSuccessResponse, SDKValidationError> {
184
+ return safeParse(
185
+ jsonString,
186
+ (x) => AuthenticateSuccessResponse$inboundSchema.parse(JSON.parse(x)),
187
+ `Failed to parse 'AuthenticateSuccessResponse' from JSON`,
188
+ );
189
+ }
@@ -5,6 +5,7 @@
5
5
  export * from "./activestatus.js";
6
6
  export * from "./alert.js";
7
7
  export * from "./appointmentsummary.js";
8
+ export * from "./authenticatesuccessresponse.js";
8
9
  export * from "./backgroundcheckresult.js";
9
10
  export * from "./company.js";
10
11
  export * from "./companycredentiallistitem.js";
@@ -89,6 +90,7 @@ export * from "./screeningansweractionsummary.js";
89
90
  export * from "./screeningquestion.js";
90
91
  export * from "./screeningresponse.js";
91
92
  export * from "./security.js";
93
+ export * from "./ssocontinuation.js";
92
94
  export * from "./standingappointment.js";
93
95
  export * from "./state.js";
94
96
  export * from "./subscription.js";
@@ -21,6 +21,39 @@ export type LoginEmailAndPassword = {
21
21
  * Password as entered by the user
22
22
  */
23
23
  password: string;
24
+ /**
25
+ * Opaque, signed state that Green Security issues when a third-party service
26
+ *
27
+ * @remarks
28
+ * provider starts a "Login with Green Security" SAML flow at
29
+ * `/saml/idp/sso`. The login screen receives it as the `sso_state` query
30
+ * string parameter and must pass it back, byte for byte, on every call to
31
+ * this endpoint for the remainder of the login journey — including the
32
+ * second call that carries an `mfa_code`.
33
+ *
34
+ * The blob is signed, not encrypted, and it expires five minutes after the
35
+ * service provider's request arrives. Do not parse it, shorten it, decode
36
+ * it, or re-encode it.
37
+ *
38
+ * **An invalid blob does not fail the login.** This is the opposite of what
39
+ * most integrators assume, so it is worth stating plainly: a forged, edited
40
+ * or expired `sso_state` is silently discarded, and the request then
41
+ * proceeds as an ordinary login. Valid credentials still authenticate and
42
+ * still return `200` — just with no `sso` object, leaving the user signed in
43
+ * to Green Security with no way back to the service provider that sent them.
44
+ * Never treat a `200` as proof that the SSO hand-off survived; check for
45
+ * `sso` explicitly.
46
+ *
47
+ * Every `202` response echoes the *verified* blob back in its own
48
+ * `sso_state` field. Always send back the value from the response you just
49
+ * received rather than the one you started with, so that a blob the server
50
+ * has already rejected is never resent, and so a client does not have to
51
+ * hold state of its own across the login journey.
52
+ *
53
+ * Omit this field entirely for an ordinary login that did not originate
54
+ * from a service provider.
55
+ */
56
+ ssoState?: string | undefined;
24
57
  };
25
58
 
26
59
  /** @internal */
@@ -28,6 +61,7 @@ export type LoginEmailAndPassword$Outbound = {
28
61
  email: string;
29
62
  mfa_code?: string | undefined;
30
63
  password: string;
64
+ sso_state?: string | undefined;
31
65
  };
32
66
 
33
67
  /** @internal */
@@ -39,9 +73,11 @@ export const LoginEmailAndPassword$outboundSchema: z.ZodType<
39
73
  email: z.string(),
40
74
  mfaCode: z.string().optional(),
41
75
  password: z.string(),
76
+ ssoState: z.string().optional(),
42
77
  }).transform((v) => {
43
78
  return remap$(v, {
44
79
  mfaCode: "mfa_code",
80
+ ssoState: "sso_state",
45
81
  });
46
82
  });
47
83
 
@@ -17,12 +17,46 @@ export type LoginRequirementsFromEmail = {
17
17
  * A proper URI where the user should be sent after completing a SAML login. This is encoded into the response you will get if the user requires a SAML login.
18
18
  */
19
19
  returnUrl: string;
20
+ /**
21
+ * Opaque, signed state that Green Security issues when a third-party service
22
+ *
23
+ * @remarks
24
+ * provider starts a "Login with Green Security" SAML flow at
25
+ * `/saml/idp/sso`. The login screen receives it as the `sso_state` query
26
+ * string parameter and must pass it back, byte for byte, on every call to
27
+ * this endpoint for the remainder of the login journey — including the
28
+ * second call that carries an `mfa_code`.
29
+ *
30
+ * The blob is signed, not encrypted, and it expires five minutes after the
31
+ * service provider's request arrives. Do not parse it, shorten it, decode
32
+ * it, or re-encode it.
33
+ *
34
+ * **An invalid blob does not fail the login.** This is the opposite of what
35
+ * most integrators assume, so it is worth stating plainly: a forged, edited
36
+ * or expired `sso_state` is silently discarded, and the request then
37
+ * proceeds as an ordinary login. Valid credentials still authenticate and
38
+ * still return `200` — just with no `sso` object, leaving the user signed in
39
+ * to Green Security with no way back to the service provider that sent them.
40
+ * Never treat a `200` as proof that the SSO hand-off survived; check for
41
+ * `sso` explicitly.
42
+ *
43
+ * Every `202` response echoes the *verified* blob back in its own
44
+ * `sso_state` field. Always send back the value from the response you just
45
+ * received rather than the one you started with, so that a blob the server
46
+ * has already rejected is never resent, and so a client does not have to
47
+ * hold state of its own across the login journey.
48
+ *
49
+ * Omit this field entirely for an ordinary login that did not originate
50
+ * from a service provider.
51
+ */
52
+ ssoState?: string | undefined;
20
53
  };
21
54
 
22
55
  /** @internal */
23
56
  export type LoginRequirementsFromEmail$Outbound = {
24
57
  email: string;
25
58
  return_url: string;
59
+ sso_state?: string | undefined;
26
60
  };
27
61
 
28
62
  /** @internal */
@@ -33,9 +67,11 @@ export const LoginRequirementsFromEmail$outboundSchema: z.ZodType<
33
67
  > = z.object({
34
68
  email: z.string(),
35
69
  returnUrl: z.string(),
70
+ ssoState: z.string().optional(),
36
71
  }).transform((v) => {
37
72
  return remap$(v, {
38
73
  returnUrl: "return_url",
74
+ ssoState: "sso_state",
39
75
  });
40
76
  });
41
77
 
@@ -36,6 +36,39 @@ export type MfaRequiredResponse = {
36
36
  */
37
37
  mobilePhone?: string | undefined;
38
38
  mfaMethod?: MfaMethod | undefined;
39
+ /**
40
+ * Opaque, signed state that Green Security issues when a third-party service
41
+ *
42
+ * @remarks
43
+ * provider starts a "Login with Green Security" SAML flow at
44
+ * `/saml/idp/sso`. The login screen receives it as the `sso_state` query
45
+ * string parameter and must pass it back, byte for byte, on every call to
46
+ * this endpoint for the remainder of the login journey — including the
47
+ * second call that carries an `mfa_code`.
48
+ *
49
+ * The blob is signed, not encrypted, and it expires five minutes after the
50
+ * service provider's request arrives. Do not parse it, shorten it, decode
51
+ * it, or re-encode it.
52
+ *
53
+ * **An invalid blob does not fail the login.** This is the opposite of what
54
+ * most integrators assume, so it is worth stating plainly: a forged, edited
55
+ * or expired `sso_state` is silently discarded, and the request then
56
+ * proceeds as an ordinary login. Valid credentials still authenticate and
57
+ * still return `200` — just with no `sso` object, leaving the user signed in
58
+ * to Green Security with no way back to the service provider that sent them.
59
+ * Never treat a `200` as proof that the SSO hand-off survived; check for
60
+ * `sso` explicitly.
61
+ *
62
+ * Every `202` response echoes the *verified* blob back in its own
63
+ * `sso_state` field. Always send back the value from the response you just
64
+ * received rather than the one you started with, so that a blob the server
65
+ * has already rejected is never resent, and so a client does not have to
66
+ * hold state of its own across the login journey.
67
+ *
68
+ * Omit this field entirely for an ordinary login that did not originate
69
+ * from a service provider.
70
+ */
71
+ ssoState?: string | undefined;
39
72
  };
40
73
 
41
74
  /** @internal */
@@ -56,10 +89,12 @@ export const MfaRequiredResponse$inboundSchema: z.ZodType<
56
89
  error: types.string(),
57
90
  mobile_phone: types.optional(types.string()),
58
91
  mfa_method: types.optional(MfaMethod$inboundSchema),
92
+ sso_state: types.optional(types.string()),
59
93
  }).transform((v) => {
60
94
  return remap$(v, {
61
95
  "mobile_phone": "mobilePhone",
62
96
  "mfa_method": "mfaMethod",
97
+ "sso_state": "ssoState",
63
98
  });
64
99
  });
65
100
 
@@ -20,9 +20,42 @@ export type PasswordNotSetResponse = {
20
20
  */
21
21
  error: string;
22
22
  /**
23
- * URL to redirect the user to set their password (forgot password flow). Includes return_url query param when provided in the request.
23
+ * URL to redirect the user to set their password (forgot password flow). Carries the `return_url` and `sso_state` query params when those were provided on the request, because the browser follows this redirect and leaves the JSON body behind.
24
24
  */
25
25
  redirectUrl: string;
26
+ /**
27
+ * Opaque, signed state that Green Security issues when a third-party service
28
+ *
29
+ * @remarks
30
+ * provider starts a "Login with Green Security" SAML flow at
31
+ * `/saml/idp/sso`. The login screen receives it as the `sso_state` query
32
+ * string parameter and must pass it back, byte for byte, on every call to
33
+ * this endpoint for the remainder of the login journey — including the
34
+ * second call that carries an `mfa_code`.
35
+ *
36
+ * The blob is signed, not encrypted, and it expires five minutes after the
37
+ * service provider's request arrives. Do not parse it, shorten it, decode
38
+ * it, or re-encode it.
39
+ *
40
+ * **An invalid blob does not fail the login.** This is the opposite of what
41
+ * most integrators assume, so it is worth stating plainly: a forged, edited
42
+ * or expired `sso_state` is silently discarded, and the request then
43
+ * proceeds as an ordinary login. Valid credentials still authenticate and
44
+ * still return `200` — just with no `sso` object, leaving the user signed in
45
+ * to Green Security with no way back to the service provider that sent them.
46
+ * Never treat a `200` as proof that the SSO hand-off survived; check for
47
+ * `sso` explicitly.
48
+ *
49
+ * Every `202` response echoes the *verified* blob back in its own
50
+ * `sso_state` field. Always send back the value from the response you just
51
+ * received rather than the one you started with, so that a blob the server
52
+ * has already rejected is never resent, and so a client does not have to
53
+ * hold state of its own across the login journey.
54
+ *
55
+ * Omit this field entirely for an ordinary login that did not originate
56
+ * from a service provider.
57
+ */
58
+ ssoState?: string | undefined;
26
59
  };
27
60
 
28
61
  /** @internal */
@@ -35,9 +68,11 @@ export const PasswordNotSetResponse$inboundSchema: z.ZodType<
35
68
  success: types.boolean(),
36
69
  error: types.string(),
37
70
  redirect_url: types.string(),
71
+ sso_state: types.optional(types.string()),
38
72
  }).transform((v) => {
39
73
  return remap$(v, {
40
74
  "redirect_url": "redirectUrl",
75
+ "sso_state": "ssoState",
41
76
  });
42
77
  });
43
78
 
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import * as z from "zod/v3";
6
+ import { remap as remap$ } from "../../lib/primitives.js";
6
7
  import { safeParse } from "../../lib/schemas.js";
7
8
  import { Result as SafeParseResult } from "../../types/fp.js";
8
9
  import * as types from "../../types/primitives.js";
@@ -18,6 +19,39 @@ export type PasswordRequiredResponse = {
18
19
  * Error describing the exact condition of what further steps are needed to finish the login process.
19
20
  */
20
21
  error: string;
22
+ /**
23
+ * Opaque, signed state that Green Security issues when a third-party service
24
+ *
25
+ * @remarks
26
+ * provider starts a "Login with Green Security" SAML flow at
27
+ * `/saml/idp/sso`. The login screen receives it as the `sso_state` query
28
+ * string parameter and must pass it back, byte for byte, on every call to
29
+ * this endpoint for the remainder of the login journey — including the
30
+ * second call that carries an `mfa_code`.
31
+ *
32
+ * The blob is signed, not encrypted, and it expires five minutes after the
33
+ * service provider's request arrives. Do not parse it, shorten it, decode
34
+ * it, or re-encode it.
35
+ *
36
+ * **An invalid blob does not fail the login.** This is the opposite of what
37
+ * most integrators assume, so it is worth stating plainly: a forged, edited
38
+ * or expired `sso_state` is silently discarded, and the request then
39
+ * proceeds as an ordinary login. Valid credentials still authenticate and
40
+ * still return `200` — just with no `sso` object, leaving the user signed in
41
+ * to Green Security with no way back to the service provider that sent them.
42
+ * Never treat a `200` as proof that the SSO hand-off survived; check for
43
+ * `sso` explicitly.
44
+ *
45
+ * Every `202` response echoes the *verified* blob back in its own
46
+ * `sso_state` field. Always send back the value from the response you just
47
+ * received rather than the one you started with, so that a blob the server
48
+ * has already rejected is never resent, and so a client does not have to
49
+ * hold state of its own across the login journey.
50
+ *
51
+ * Omit this field entirely for an ordinary login that did not originate
52
+ * from a service provider.
53
+ */
54
+ ssoState?: string | undefined;
21
55
  };
22
56
 
23
57
  /** @internal */
@@ -29,6 +63,11 @@ export const PasswordRequiredResponse$inboundSchema: z.ZodType<
29
63
  requires: types.literal("password"),
30
64
  success: types.boolean(),
31
65
  error: types.string(),
66
+ sso_state: types.optional(types.string()),
67
+ }).transform((v) => {
68
+ return remap$(v, {
69
+ "sso_state": "ssoState",
70
+ });
32
71
  });
33
72
 
34
73
  export function passwordRequiredResponseFromJSON(
@@ -28,6 +28,39 @@ export type SamlLoginRequiredResponse = {
28
28
  * This is the URL that should be opened to initiate the SAML login flow
29
29
  */
30
30
  ssoUrl: string;
31
+ /**
32
+ * Opaque, signed state that Green Security issues when a third-party service
33
+ *
34
+ * @remarks
35
+ * provider starts a "Login with Green Security" SAML flow at
36
+ * `/saml/idp/sso`. The login screen receives it as the `sso_state` query
37
+ * string parameter and must pass it back, byte for byte, on every call to
38
+ * this endpoint for the remainder of the login journey — including the
39
+ * second call that carries an `mfa_code`.
40
+ *
41
+ * The blob is signed, not encrypted, and it expires five minutes after the
42
+ * service provider's request arrives. Do not parse it, shorten it, decode
43
+ * it, or re-encode it.
44
+ *
45
+ * **An invalid blob does not fail the login.** This is the opposite of what
46
+ * most integrators assume, so it is worth stating plainly: a forged, edited
47
+ * or expired `sso_state` is silently discarded, and the request then
48
+ * proceeds as an ordinary login. Valid credentials still authenticate and
49
+ * still return `200` — just with no `sso` object, leaving the user signed in
50
+ * to Green Security with no way back to the service provider that sent them.
51
+ * Never treat a `200` as proof that the SSO hand-off survived; check for
52
+ * `sso` explicitly.
53
+ *
54
+ * Every `202` response echoes the *verified* blob back in its own
55
+ * `sso_state` field. Always send back the value from the response you just
56
+ * received rather than the one you started with, so that a blob the server
57
+ * has already rejected is never resent, and so a client does not have to
58
+ * hold state of its own across the login journey.
59
+ *
60
+ * Omit this field entirely for an ordinary login that did not originate
61
+ * from a service provider.
62
+ */
63
+ ssoState?: string | undefined;
31
64
  };
32
65
 
33
66
  /** @internal */
@@ -41,10 +74,12 @@ export const SamlLoginRequiredResponse$inboundSchema: z.ZodType<
41
74
  error: types.string(),
42
75
  sso_instructions: types.optional(types.string()),
43
76
  sso_url: types.string(),
77
+ sso_state: types.optional(types.string()),
44
78
  }).transform((v) => {
45
79
  return remap$(v, {
46
80
  "sso_instructions": "ssoInstructions",
47
81
  "sso_url": "ssoUrl",
82
+ "sso_state": "ssoState",
48
83
  });
49
84
  });
50
85
 
@@ -0,0 +1,71 @@
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 { Result as SafeParseResult } from "../../types/fp.js";
9
+ import * as types from "../../types/primitives.js";
10
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
+
12
+ /**
13
+ * Where to send the browser to finish a "Login with Green Security" flow.
14
+ *
15
+ * @remarks
16
+ *
17
+ * Present on a `200` from `POST /users/authenticate` only when the request
18
+ * carried a valid, unexpired `sso_state`. Its absence means the login
19
+ * succeeded but the SAML flow did not resume — treat the login as an
20
+ * ordinary one rather than retrying.
21
+ *
22
+ * This object is additive. The login itself is unaffected by it: the
23
+ * caller's own permanent token is in `user_token` exactly as it would be on
24
+ * any other successful authentication, and it is not the token embedded in
25
+ * `continue_url`.
26
+ */
27
+ export type SsoContinuation = {
28
+ /**
29
+ * An absolute, single-use URL on Green Security's domain. Navigate the
30
+ *
31
+ * @remarks
32
+ * browser to it (a full page navigation, not `fetch`); it answers with a
33
+ * self-submitting form that POSTs the signed `SAMLResponse` and the
34
+ * original `RelayState` to the service provider's assertion consumer
35
+ * service URL.
36
+ *
37
+ * The `token` in this URL is a separate **one-time** token that is
38
+ * consumed the first time the URL is followed, so the URL is good for
39
+ * exactly one navigation. It is not the caller's permanent token, which
40
+ * is returned unchanged in `user_token`. Treat the URL as a secret:
41
+ * whoever follows it first receives that user's assertion.
42
+ *
43
+ * Never fetch this URL from your own back end: the response is meant for
44
+ * the user's browser, and posting the assertion from anywhere else
45
+ * breaks the flow.
46
+ */
47
+ continueUrl: string;
48
+ };
49
+
50
+ /** @internal */
51
+ export const SsoContinuation$inboundSchema: z.ZodType<
52
+ SsoContinuation,
53
+ z.ZodTypeDef,
54
+ unknown
55
+ > = z.object({
56
+ continue_url: types.string(),
57
+ }).transform((v) => {
58
+ return remap$(v, {
59
+ "continue_url": "continueUrl",
60
+ });
61
+ });
62
+
63
+ export function ssoContinuationFromJSON(
64
+ jsonString: string,
65
+ ): SafeParseResult<SsoContinuation, SDKValidationError> {
66
+ return safeParse(
67
+ jsonString,
68
+ (x) => SsoContinuation$inboundSchema.parse(JSON.parse(x)),
69
+ `Failed to parse 'SsoContinuation' from JSON`,
70
+ );
71
+ }
@@ -26,7 +26,7 @@ export type PostAuthenticateResponseBody =
26
26
  | components.PasswordNotSetResponse;
27
27
 
28
28
  export type PostAuthenticateResponse =
29
- | components.User
29
+ | components.AuthenticateSuccessResponse
30
30
  | components.MfaRequiredResponse
31
31
  | components.SamlLoginRequiredResponse
32
32
  | components.PasswordRequiredResponse
@@ -85,7 +85,7 @@ export const PostAuthenticateResponse$inboundSchema: z.ZodType<
85
85
  z.ZodTypeDef,
86
86
  unknown
87
87
  > = smartUnion([
88
- components.User$inboundSchema,
88
+ components.AuthenticateSuccessResponse$inboundSchema,
89
89
  z.union([
90
90
  components.MfaRequiredResponse$inboundSchema,
91
91
  components.SamlLoginRequiredResponse$inboundSchema,
@@ -81,6 +81,43 @@ export type UsersPostAuthenticateMutationError =
81
81
  * 3. Site redirects to your selected `return_url`
82
82
  * 4. The `user_token` will be appended as a query string parameter to your `return_url` - you must parse this token and store it
83
83
  * 5. Fetch the user object from `/users/me` using the token
84
+ *
85
+ * ## Finishing a "Login with Green Security" flow
86
+ *
87
+ * Green Security is also a SAML2 **identity provider**. When a third-party service provider sends a user to
88
+ * `/saml/idp/sso` to sign in with their Green Security account, the user lands on a Green Security login screen
89
+ * carrying an `sso_state` query string parameter. That parameter is a signed, five-minute record of which service
90
+ * provider is waiting, where its assertion consumer service lives, and what `RelayState` it sent.
91
+ *
92
+ * Authentication itself is unchanged - the user may still need a password, an MFA code, a magic link or a round trip
93
+ * to their own SAML IdP, and every `requires` value above applies as normal. The only difference is that you must
94
+ * echo `sso_state` back on **every** call in the sequence, unchanged, including the follow-up that carries the
95
+ * `mfa_code`.
96
+ *
97
+ * Each `202` response carries the verified blob back to you in its own top-level `sso_state` field. Send back the
98
+ * value from the response you just received rather than the one you started with. The two are normally the same
99
+ * string, but re-sending your original copy is how a blob the server has already rejected gets resent, and it forces
100
+ * you to hold login state you would otherwise not need.
101
+ *
102
+ * 1. Read `sso_state` from the query string of the login screen you were sent to
103
+ * 2. Run the login exactly as you would otherwise, adding `sso_state` to each request body and taking the value for
104
+ * the next request from the previous `202` response
105
+ * 3. On the `200` response, read `sso.continue_url`
106
+ * 4. Navigate the browser to `sso.continue_url` - a full page navigation, not a background fetch. It answers with a
107
+ * self-submitting form that delivers the signed `SAMLResponse` and the original `RelayState` to the service
108
+ * provider
109
+ * 5. The service provider validates the assertion and the user is signed in on their side
110
+ *
111
+ * On the `password_reset` leg the blob is **also** appended to `redirect_url` as a query parameter, alongside
112
+ * `return_url`. The browser follows that redirect and leaves the JSON body behind, so anything the remaining legs of
113
+ * the login still need has to ride the URL. Preserve the query string exactly as given.
114
+ *
115
+ * An invalid `sso_state` never fails a login. A forged, edited or expired blob is silently dropped and the request is
116
+ * then treated as an ordinary login, so valid credentials still return `200` - just with no `sso` object. Check for
117
+ * `sso` explicitly rather than reading `200` as proof the hand-off survived. When it is absent, do not retry with the
118
+ * same blob; the user has to start again from the service provider. See the
119
+ * [Login with Green Security](https://greensecurity.apidocumentation.com/guides/sso-login-with-green-security)
120
+ * guide for the service provider half of this flow.
84
121
  */
85
122
  export function useUsersPostAuthenticateMutation(
86
123
  options?: MutationHookOptions<