Skip to content

Commit 43732bd

Browse files
Add fetch for query signup parameters (#29)
1 parent b839421 commit 43732bd

File tree

4 files changed

+96
-57
lines changed

4 files changed

+96
-57
lines changed

package.json

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
{
2-
"name": "@propelauth/node",
3-
"repository": {
4-
"type": "git",
5-
"url": "https://github.com/PropelAuth/node"
6-
},
7-
"version": "2.1.8",
8-
"license": "MIT",
9-
"keywords": [
10-
"auth",
11-
"node",
12-
"user"
13-
],
14-
"dependencies": {
15-
"jsonwebtoken": "^9.0.0"
16-
},
17-
"devDependencies": {
18-
"@rollup/plugin-commonjs": "^19.0.0",
19-
"@rollup/plugin-node-resolve": "^13.0.0",
20-
"@rollup/plugin-typescript": "^8.2.1",
21-
"@types/express": "^4.17.11",
22-
"@types/jest": "^27.0.1",
23-
"@types/jsonwebtoken": "^8.5.1",
24-
"@types/uuid": "^8.3.1",
25-
"jest": "^27.0.6",
26-
"nock": "^13.1.2",
27-
"prettier": "^2.3.2",
28-
"prettier-plugin-organize-imports": "^2.3.3",
29-
"rimraf": "^3.0.2",
30-
"rollup": "^2.52.7",
31-
"rollup-plugin-peer-deps-external": "^2.2.4",
32-
"ts-jest": "^27.0.5",
33-
"typescript": "^4.2.4",
34-
"uuid": "^8.3.2"
35-
},
36-
"scripts": {
37-
"type-check": "tsc --noEmit",
38-
"type-check:watch": "npm run type-check -- --watch",
39-
"build:types": "tsc --emitDeclarationOnly",
40-
"build:js": "rollup -c",
41-
"build": "npm run test && npm run build:types && npm run build:js",
42-
"test": "jest --silent",
43-
"prepublishOnly": "npm run build"
44-
},
45-
"main": "dist/index.js",
46-
"module": "dist/index.es.js",
47-
"files": [
48-
"dist"
49-
],
50-
"jest": {
51-
"testMatch": [
52-
"**/test/*.ts"
2+
"name": "@propelauth/node",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/PropelAuth/node"
6+
},
7+
"version": "2.1.9",
8+
"license": "MIT",
9+
"keywords": [
10+
"auth",
11+
"node",
12+
"user"
5313
],
54-
"moduleFileExtensions": [
55-
"ts",
56-
"js"
14+
"dependencies": {
15+
"jsonwebtoken": "^9.0.0"
16+
},
17+
"devDependencies": {
18+
"@rollup/plugin-commonjs": "^19.0.0",
19+
"@rollup/plugin-node-resolve": "^13.0.0",
20+
"@rollup/plugin-typescript": "^8.2.1",
21+
"@types/express": "^4.17.11",
22+
"@types/jest": "^27.0.1",
23+
"@types/jsonwebtoken": "^8.5.1",
24+
"@types/uuid": "^8.3.1",
25+
"jest": "^27.0.6",
26+
"nock": "^13.1.2",
27+
"prettier": "^2.3.2",
28+
"prettier-plugin-organize-imports": "^2.3.3",
29+
"rimraf": "^3.0.2",
30+
"rollup": "^2.52.7",
31+
"rollup-plugin-peer-deps-external": "^2.2.4",
32+
"ts-jest": "^27.0.5",
33+
"typescript": "^4.2.4",
34+
"uuid": "^8.3.2"
35+
},
36+
"scripts": {
37+
"type-check": "tsc --noEmit",
38+
"type-check:watch": "npm run type-check -- --watch",
39+
"build:types": "tsc --emitDeclarationOnly",
40+
"build:js": "rollup -c",
41+
"build": "npm run test && npm run build:types && npm run build:js",
42+
"test": "jest --silent",
43+
"prepublishOnly": "npm run build"
44+
},
45+
"main": "dist/index.js",
46+
"module": "dist/index.es.js",
47+
"files": [
48+
"dist"
5749
],
58-
"transform": {
59-
"^.+\\.(ts|tsx)?$": "ts-jest"
50+
"jest": {
51+
"testMatch": [
52+
"**/test/*.ts"
53+
],
54+
"moduleFileExtensions": [
55+
"ts",
56+
"js"
57+
],
58+
"transform": {
59+
"^.+\\.(ts|tsx)?$": "ts-jest"
60+
}
6061
}
61-
}
6262
}

src/api/user.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,34 @@ export function deleteUser(authUrl: URL, integrationApiKey: string, userId: stri
511511
return true
512512
})
513513
}
514+
515+
export type UserSignupQueryParams = {
516+
userSignupQueryParameters: { [key: string]: string }
517+
}
518+
519+
export async function fetchUserSignupQueryParams(
520+
authUrl: URL,
521+
integrationApiKey: string,
522+
userId: string
523+
): Promise<UserSignupQueryParams | null> {
524+
if (!isValidId(userId)) {
525+
return Promise.resolve(null)
526+
}
527+
528+
const httpResponse = await httpRequest(
529+
authUrl,
530+
integrationApiKey,
531+
`${ENDPOINT_PATH}/${userId}/signup_query_parameters`,
532+
"GET"
533+
)
534+
if (httpResponse.statusCode === 401) {
535+
throw new Error("integrationApiKey is incorrect")
536+
} else if (httpResponse.statusCode === 404) {
537+
return null
538+
} else if (httpResponse.statusCode && httpResponse.statusCode >= 400) {
539+
throw new Error("Unknown error when fetching user signup query params")
540+
}
541+
542+
const snakeCase = JSON.parse(httpResponse.response)
543+
return { userSignupQueryParameters: snakeCase["user_signup_query_parameters"] }
544+
}

src/auth.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
fetchUserMetadataByQuery,
4949
fetchUserMetadataByUserIdWithIdCheck,
5050
fetchUsersByQuery,
51+
fetchUserSignupQueryParams,
5152
fetchUsersInOrg,
5253
inviteUserToOrg,
5354
InviteUserToOrgRequest,
@@ -57,6 +58,7 @@ import {
5758
UpdateUserMetadataRequest,
5859
updateUserPassword,
5960
UpdateUserPasswordRequest,
61+
UserSignupQueryParams,
6062
UsersInOrgQuery,
6163
UsersPagedResponse,
6264
UsersQuery,
@@ -142,6 +144,10 @@ export function initBaseAuth(opts: BaseAuthOptions) {
142144
})
143145
}
144146

147+
function fetchUserSignupQueryParamsWrapper(userId: string): Promise<UserSignupQueryParams | null> {
148+
return fetchUserSignupQueryParams(authUrl, integrationApiKey, userId)
149+
}
150+
145151
function fetchBatchUserMetadataByUserIds(
146152
userIds: string[],
147153
includeOrgs?: boolean
@@ -349,6 +355,7 @@ export function initBaseAuth(opts: BaseAuthOptions) {
349355
fetchUserMetadataByUserId,
350356
fetchUserMetadataByEmail,
351357
fetchUserMetadataByUsername,
358+
fetchUserSignupQueryParams: fetchUserSignupQueryParamsWrapper,
352359
fetchBatchUserMetadataByUserIds,
353360
fetchBatchUserMetadataByEmails,
354361
fetchBatchUserMetadataByUsernames,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
InviteUserToOrgRequest,
88
UpdateUserEmailRequest,
99
UpdateUserMetadataRequest,
10+
UserSignupQueryParams,
1011
UsersInOrgQuery,
1112
UsersPagedResponse,
1213
UsersQuery,

0 commit comments

Comments
 (0)