-
Notifications
You must be signed in to change notification settings - Fork 393
Implemented the listRulesetMetadata() API #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,11 @@ export interface RulesetResponse extends RulesetContent { | |
readonly createTime: string; | ||
} | ||
|
||
export interface ListRulesetsResponse { | ||
readonly rulesets: Array<{name: string, createTime: string}>; | ||
readonly nextPageToken?: string; | ||
} | ||
|
||
/** | ||
* Class that facilitates sending requests to the Firebase security rules backend API. | ||
* | ||
|
@@ -119,6 +124,38 @@ export class SecurityRulesApiClient { | |
}); | ||
} | ||
|
||
public listRulesets(pageSize: number = 100, pageToken?: string): Promise<ListRulesetsResponse> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you even want to allow users to customize this number? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point. This was approved during the API review process on the grounds that other similar APIs in the admin SDK (e.g. |
||
if (!validator.isNumber(pageSize)) { | ||
const err = new FirebaseSecurityRulesError('invalid-argument', 'Invalid page size.'); | ||
return Promise.reject(err); | ||
} | ||
if (pageSize < 1 || pageSize > 100) { | ||
const err = new FirebaseSecurityRulesError( | ||
'invalid-argument', 'Page size must be between 1 and 100.'); | ||
return Promise.reject(err); | ||
} | ||
if (typeof pageToken !== 'undefined' && !validator.isNonEmptyString(pageToken)) { | ||
const err = new FirebaseSecurityRulesError( | ||
'invalid-argument', 'Next page token must be a non-empty string.'); | ||
return Promise.reject(err); | ||
} | ||
|
||
const data = { | ||
pageSize, | ||
pageToken, | ||
}; | ||
if (!pageToken) { | ||
delete data.pageToken; | ||
} | ||
|
||
const request: HttpRequestConfig = { | ||
method: 'GET', | ||
url: `${this.url}/rulesets`, | ||
data, | ||
}; | ||
return this.sendRequest<ListRulesetsResponse>(request); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider providing a convenience method that repeatedly paginates until the end and then returns the entire list There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We haven't really done that sort of thing in Node.js before. But that's something we can certainly consider in the future. I think we haven't done this for APIs like In some of the other languages like Java and Python we already have established iterable/iterator patterns to support this use case cleanly. e.g. https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/auth/ListUsersPage.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clever |
||
} | ||
|
||
public getRelease(name: string): Promise<Release> { | ||
return this.getResource<Release>(`releases/${name}`); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.