-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update data source for
getSuggestedFollowsByActor
(#2630)
* Update lex * Codegen * Set up StatSig * Integrate new implementation into old endpoint * Add todo to crypto module * Format * Specify StatSig env * Downgrade pnpm to match CI, bump lock * Catch StatSig errors * Use sep env * Reset lockfile * Re-add new dep using correct pnpm version * tidy * Integrate into AppContext and lifecycle * Use camelCase * Switcheroo Co-authored-by: devin ivy <devinivy@gmail.com> * Init prior to server listen start * Move test env check up to server config * Add logger and log * Better comment --------- Co-authored-by: devin ivy <devinivy@gmail.com>
- Loading branch information
1 parent
2f40203
commit 8f22a25
Showing
18 changed files
with
221 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Statsig, StatsigUser } from 'statsig-node' | ||
import { sha256Hex } from '@atproto/crypto' | ||
|
||
import { featureGatesLogger } from './logger' | ||
import type { ServerConfig } from './config' | ||
|
||
export type Config = { | ||
apiKey?: string | ||
env?: 'development' | 'staging' | 'production' | string | ||
} | ||
|
||
export enum GateID { | ||
NewSuggestedFollowsByActor = 'new_sugg_foll_by_actor', | ||
} | ||
|
||
/** | ||
* @see https://docs.statsig.com/server/nodejsServerSDK | ||
*/ | ||
export class FeatureGates { | ||
ready = false | ||
private statsig = Statsig | ||
ids = GateID | ||
|
||
constructor(private config: Config) {} | ||
|
||
async start() { | ||
try { | ||
if (this.config.apiKey) { | ||
/** | ||
* Special handling in test mode, see {@link ServerConfig} | ||
* | ||
* {@link https://docs.statsig.com/server/nodejsServerSDK#local-overrides} | ||
*/ | ||
await this.statsig.initialize(this.config.apiKey, { | ||
localMode: this.config.env === 'test', | ||
environment: { | ||
tier: this.config.env || 'development', | ||
}, | ||
}) | ||
this.ready = true | ||
} | ||
} catch (err) { | ||
featureGatesLogger.error({ err }, 'Failed to initialize StatSig') | ||
this.ready = false | ||
} | ||
} | ||
|
||
destroy() { | ||
if (this.ready) { | ||
this.ready = false | ||
this.statsig.shutdown() | ||
} | ||
} | ||
|
||
async user({ did }: { did: string }): Promise<StatsigUser> { | ||
const userID = await sha256Hex(did) | ||
return { | ||
userID, | ||
} | ||
} | ||
|
||
check(user: StatsigUser, gate: GateID) { | ||
if (!this.ready) return false | ||
return this.statsig.checkGateSync(user, gate) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.