Skip to content

Commit

Permalink
Add fetch for query signup parameters (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-propelauth authored Jan 29, 2024
1 parent b839421 commit 43732bd
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 57 deletions.
114 changes: 57 additions & 57 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
{
"name": "@propelauth/node",
"repository": {
"type": "git",
"url": "https:/PropelAuth/node"
},
"version": "2.1.8",
"license": "MIT",
"keywords": [
"auth",
"node",
"user"
],
"dependencies": {
"jsonwebtoken": "^9.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/express": "^4.17.11",
"@types/jest": "^27.0.1",
"@types/jsonwebtoken": "^8.5.1",
"@types/uuid": "^8.3.1",
"jest": "^27.0.6",
"nock": "^13.1.2",
"prettier": "^2.3.2",
"prettier-plugin-organize-imports": "^2.3.3",
"rimraf": "^3.0.2",
"rollup": "^2.52.7",
"rollup-plugin-peer-deps-external": "^2.2.4",
"ts-jest": "^27.0.5",
"typescript": "^4.2.4",
"uuid": "^8.3.2"
},
"scripts": {
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "rollup -c",
"build": "npm run test && npm run build:types && npm run build:js",
"test": "jest --silent",
"prepublishOnly": "npm run build"
},
"main": "dist/index.js",
"module": "dist/index.es.js",
"files": [
"dist"
],
"jest": {
"testMatch": [
"**/test/*.ts"
"name": "@propelauth/node",
"repository": {
"type": "git",
"url": "https:/PropelAuth/node"
},
"version": "2.1.9",
"license": "MIT",
"keywords": [
"auth",
"node",
"user"
],
"moduleFileExtensions": [
"ts",
"js"
"dependencies": {
"jsonwebtoken": "^9.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/express": "^4.17.11",
"@types/jest": "^27.0.1",
"@types/jsonwebtoken": "^8.5.1",
"@types/uuid": "^8.3.1",
"jest": "^27.0.6",
"nock": "^13.1.2",
"prettier": "^2.3.2",
"prettier-plugin-organize-imports": "^2.3.3",
"rimraf": "^3.0.2",
"rollup": "^2.52.7",
"rollup-plugin-peer-deps-external": "^2.2.4",
"ts-jest": "^27.0.5",
"typescript": "^4.2.4",
"uuid": "^8.3.2"
},
"scripts": {
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "rollup -c",
"build": "npm run test && npm run build:types && npm run build:js",
"test": "jest --silent",
"prepublishOnly": "npm run build"
},
"main": "dist/index.js",
"module": "dist/index.es.js",
"files": [
"dist"
],
"transform": {
"^.+\\.(ts|tsx)?$": "ts-jest"
"jest": {
"testMatch": [
"**/test/*.ts"
],
"moduleFileExtensions": [
"ts",
"js"
],
"transform": {
"^.+\\.(ts|tsx)?$": "ts-jest"
}
}
}
}
31 changes: 31 additions & 0 deletions src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,34 @@ export function deleteUser(authUrl: URL, integrationApiKey: string, userId: stri
return true
})
}

export type UserSignupQueryParams = {
userSignupQueryParameters: { [key: string]: string }
}

export async function fetchUserSignupQueryParams(
authUrl: URL,
integrationApiKey: string,
userId: string
): Promise<UserSignupQueryParams | null> {
if (!isValidId(userId)) {
return Promise.resolve(null)
}

const httpResponse = await httpRequest(
authUrl,
integrationApiKey,
`${ENDPOINT_PATH}/${userId}/signup_query_parameters`,
"GET"
)
if (httpResponse.statusCode === 401) {
throw new Error("integrationApiKey is incorrect")
} else if (httpResponse.statusCode === 404) {
return null
} else if (httpResponse.statusCode && httpResponse.statusCode >= 400) {
throw new Error("Unknown error when fetching user signup query params")
}

const snakeCase = JSON.parse(httpResponse.response)
return { userSignupQueryParameters: snakeCase["user_signup_query_parameters"] }
}
7 changes: 7 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
fetchUserMetadataByQuery,
fetchUserMetadataByUserIdWithIdCheck,
fetchUsersByQuery,
fetchUserSignupQueryParams,
fetchUsersInOrg,
inviteUserToOrg,
InviteUserToOrgRequest,
Expand All @@ -57,6 +58,7 @@ import {
UpdateUserMetadataRequest,
updateUserPassword,
UpdateUserPasswordRequest,
UserSignupQueryParams,
UsersInOrgQuery,
UsersPagedResponse,
UsersQuery,
Expand Down Expand Up @@ -142,6 +144,10 @@ export function initBaseAuth(opts: BaseAuthOptions) {
})
}

function fetchUserSignupQueryParamsWrapper(userId: string): Promise<UserSignupQueryParams | null> {
return fetchUserSignupQueryParams(authUrl, integrationApiKey, userId)
}

function fetchBatchUserMetadataByUserIds(
userIds: string[],
includeOrgs?: boolean
Expand Down Expand Up @@ -349,6 +355,7 @@ export function initBaseAuth(opts: BaseAuthOptions) {
fetchUserMetadataByUserId,
fetchUserMetadataByEmail,
fetchUserMetadataByUsername,
fetchUserSignupQueryParams: fetchUserSignupQueryParamsWrapper,
fetchBatchUserMetadataByUserIds,
fetchBatchUserMetadataByEmails,
fetchBatchUserMetadataByUsernames,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
InviteUserToOrgRequest,
UpdateUserEmailRequest,
UpdateUserMetadataRequest,
UserSignupQueryParams,
UsersInOrgQuery,
UsersPagedResponse,
UsersQuery,
Expand Down

0 comments on commit 43732bd

Please sign in to comment.