type
stringclasses
7 values
content
stringlengths
4
9.55k
repo
stringlengths
7
96
path
stringlengths
4
178
language
stringclasses
1 value
FunctionDeclaration
export function StartupServiceFactory(startupService: StartupService): Function { return () => startupService.load(); }
lzw3232/tinyNet-master
src/app/app.module.ts
TypeScript
ArrowFunction
() => startupService.load()
lzw3232/tinyNet-master
src/app/app.module.ts
TypeScript
ClassDeclaration
@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, HttpClientModule, DelonModule.forRoot(), CoreModule, SharedModule, LayoutModule, RoutesModule, ...FORM_MODULES, ...GLOBAL_THIRD_MDOULES ], providers: [ ...LANG_PROVIDES, ...INTERCEPTOR_PROVIDES, ...APPINIT_PROVIDES, // ...MY_PROVIDES { provide: RouteReuseStrategy, useClass: ReuseTabStrategy, deps: [ReuseTabService], } ], bootstrap: [AppComponent] }) export class AppModule { }
lzw3232/tinyNet-master
src/app/app.module.ts
TypeScript
FunctionDeclaration
/** * Create a reader that can return blocks in base64url format. * @param stream {Readable} a stream to read blocks * @param blockSize {number} the aproximate size of the block (will be converted for the closest multiple of 3). */ export async function createBase64BlockReader(stream: Readable, blockSize: number): Promise<Base64BlockReader> { return new Promise((resolve, reject) => { stream.on('readable', () => { resolve(new Base64BlockReader(stream, Math.round(blockSize / 3) * 3)); }); stream.on('error', err => { reject(err); }); }); }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
ArrowFunction
(resolve, reject) => { stream.on('readable', () => { resolve(new Base64BlockReader(stream, Math.round(blockSize / 3) * 3)); }); stream.on('error', err => { reject(err); }); }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
ArrowFunction
() => { resolve(new Base64BlockReader(stream, Math.round(blockSize / 3) * 3)); }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
ArrowFunction
err => { reject(err); }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
ClassDeclaration
class Base64BlockReader { constructor( private stream: Readable, private blockSize: number) { if (!stream.readable) throw new Error('stream need to be readable.'); if (blockSize % 3 !== 0) throw new Error('blockSize need to be multiple of 3.'); } private _formatBase64Url(block: Buffer) { return block.toString('base64') .replace(/=/g, "") .replace(/\+/g, "-") .replace(/\//g, "_"); } read() { let block = this.stream.read(this.blockSize); if (!block) { block = this.stream.read(); if (!block) return null; } if (Buffer.isBuffer(block)) { return this._formatBase64Url(block); } return this._formatBase64Url(Buffer.from(block, 'utf-8')); } readAll() { const blocks = <Blocks>[]; blocks.totalLength = 0; let block; while (block = this.read()) { blocks.push(block); blocks.totalLength += block.length; } return blocks; } get readableLength() { return this.stream.readableLength; } }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
InterfaceDeclaration
export interface Blocks extends Array<string> { totalLength: number; }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
MethodDeclaration
private _formatBase64Url(block: Buffer) { return block.toString('base64') .replace(/=/g, "") .replace(/\+/g, "-") .replace(/\//g, "_"); }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
MethodDeclaration
read() { let block = this.stream.read(this.blockSize); if (!block) { block = this.stream.read(); if (!block) return null; } if (Buffer.isBuffer(block)) { return this._formatBase64Url(block); } return this._formatBase64Url(Buffer.from(block, 'utf-8')); }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
MethodDeclaration
readAll() { const blocks = <Blocks>[]; blocks.totalLength = 0; let block; while (block = this.read()) { blocks.push(block); blocks.totalLength += block.length; } return blocks; }
jonataspiazzi/pocs
node/base-64-reader/src/base64BlockReader.ts
TypeScript
InterfaceDeclaration
export interface EbbinghausItem { id?: number; name: string; link?: string; desc?: string; createTime: number | Date; updateTime: number | Date; stage: Stage; }
ycycwx/ebbinghaus
types/store.ts
TypeScript
TypeAliasDeclaration
export type Stage = 1 | 2 | 4 | 7 | 15 | 1_000_000_000;
ycycwx/ebbinghaus
types/store.ts
TypeScript
ArrowFunction
apiResponse => { // Save user data this.ObservablesService.setObservableData('users', apiResponse.data); // Navigation to protected route this.Router.navigateByUrl('/'); }
maximelouasse/mysponsport
ANGclient/src/app/app.component.ts
TypeScript
ArrowFunction
error => { console.log("Auto connection fail", error); // Navigation to protected route this.Router.navigateByUrl('/connexion'); }
maximelouasse/mysponsport
ANGclient/src/app/app.component.ts
TypeScript
ClassDeclaration
// /* Componant configuration */ @Component({ selector: 'app-root', template: ` <app-sidebar></app-sidebar> <app-header></app-header> <router-outlet></router-outlet> ` }) // /* Componant class definition */ export class AppComponent { title = 'MySponsport'; constructor( private ObservablesService: ObservablesService, private AuthService: AuthService, private Router: Router ) {} async ngOnInit() { console.log(localStorage.getItem('userId')); if(localStorage.getItem('userId') != null) { this.AuthService.identity(localStorage.getItem('userId')) .then( apiResponse => { // Save user data this.ObservablesService.setObservableData('users', apiResponse.data); // Navigation to protected route this.Router.navigateByUrl('/'); }) .catch( error => { console.log("Auto connection fail", error); // Navigation to protected route this.Router.navigateByUrl('/connexion'); }); } } }
maximelouasse/mysponsport
ANGclient/src/app/app.component.ts
TypeScript
MethodDeclaration
async ngOnInit() { console.log(localStorage.getItem('userId')); if(localStorage.getItem('userId') != null) { this.AuthService.identity(localStorage.getItem('userId')) .then( apiResponse => { // Save user data this.ObservablesService.setObservableData('users', apiResponse.data); // Navigation to protected route this.Router.navigateByUrl('/'); }) .catch( error => { console.log("Auto connection fail", error); // Navigation to protected route this.Router.navigateByUrl('/connexion'); }); } }
maximelouasse/mysponsport
ANGclient/src/app/app.component.ts
TypeScript
ArrowFunction
(name: string): pino.Logger => { return pino({ name: name, level: process.env.LOG_LEVEL || "info", mixin() { return { version: pjson.version, node_env: process.env.NODE_ENV, }; }, }); }
BuzzyApp/iap-microservice
src/logging.ts
TypeScript
MethodDeclaration
mixin() { return { version: pjson.version, node_env: process.env.NODE_ENV, }; }
BuzzyApp/iap-microservice
src/logging.ts
TypeScript
ArrowFunction
() => { let connections: Connection[]; before(async () => connections = await createTestingConnections({ enabledDrivers: ["postgres", "mariadb", "mysql"], entities: [Men, Person, Women], schema: "custom", schemaCreate: true })); beforeEach(() => reloadTestingDatabases(connections)); after(() => closeTestingConnections(connections)); it("Child classes should have same schema as parent", () => Promise.all(connections.map(async connection => { const personMetadata = connection.getMetadata(Person); const menMetadata = connection.getMetadata(Men); const womenMetadata = connection.getMetadata(Women); // @ts-ignore personMetadata.schema.should.be.eq("custom"); // @ts-ignore menMetadata.schema.should.be.eq(personMetadata.schema); // @ts-ignore womenMetadata.schema.should.be.eq(personMetadata.schema); }))); }
DavisSylvester/typeorm
test/github-issues/3857/issue-3857.ts
TypeScript
ArrowFunction
async () => connections = await createTestingConnections({ enabledDrivers: ["postgres", "mariadb", "mysql"], entities: [Men, Person, Women], schema: "custom", schemaCreate: true })
DavisSylvester/typeorm
test/github-issues/3857/issue-3857.ts
TypeScript
ArrowFunction
() => Promise.all(connections.map(async connection => { const personMetadata = connection.getMetadata(Person); const menMetadata = connection.getMetadata(Men); const womenMetadata = connection.getMetadata(Women); // @ts-ignore personMetadata.schema.should.be.eq("custom"); // @ts-ignore menMetadata.schema.should.be.eq(personMetadata.schema); // @ts-ignore womenMetadata.schema.should.be.eq(personMetadata.schema); }))
DavisSylvester/typeorm
test/github-issues/3857/issue-3857.ts
TypeScript
ArrowFunction
async connection => { const personMetadata = connection.getMetadata(Person); const menMetadata = connection.getMetadata(Men); const womenMetadata = connection.getMetadata(Women); // @ts-ignore personMetadata.schema.should.be.eq("custom"); // @ts-ignore menMetadata.schema.should.be.eq(personMetadata.schema); // @ts-ignore womenMetadata.schema.should.be.eq(personMetadata.schema); }
DavisSylvester/typeorm
test/github-issues/3857/issue-3857.ts
TypeScript
ArrowFunction
(mardown: MarkdownIt) => { if (this.options.markdown !== false) mardown.enable('emphasis'); }
hedeqiang/am-editor
plugins/bold/src/index.ts
TypeScript
ClassDeclaration
export default class< T extends BoldOptions = BoldOptions, > extends MarkPlugin<T> { static get pluginName() { return 'bold'; } tagName = 'strong'; init(): void { super.init(); const editor = this.editor; if (isEngine(editor)) { editor.on(MARKDOWN_IT, this.markdownIt); } } markdownIt = (mardown: MarkdownIt) => { if (this.options.markdown !== false) mardown.enable('emphasis'); }; hotkey() { return this.options.hotkey || 'mod+b'; } conversion() { return [ { from: { span: { style: { 'font-weight': ['bold', '700'], }, }, }, to: this.tagName, }, { from: 'b', to: this.tagName, }, ]; } destroy(): void { this.editor.off(MARKDOWN_IT, this.markdownIt); } }
hedeqiang/am-editor
plugins/bold/src/index.ts
TypeScript
InterfaceDeclaration
export interface BoldOptions extends PluginOptions { hotkey?: string | Array<string>; markdown?: boolean; }
hedeqiang/am-editor
plugins/bold/src/index.ts
TypeScript
MethodDeclaration
init(): void { super.init(); const editor = this.editor; if (isEngine(editor)) { editor.on(MARKDOWN_IT, this.markdownIt); } }
hedeqiang/am-editor
plugins/bold/src/index.ts
TypeScript
MethodDeclaration
hotkey() { return this.options.hotkey || 'mod+b'; }
hedeqiang/am-editor
plugins/bold/src/index.ts
TypeScript
MethodDeclaration
conversion() { return [ { from: { span: { style: { 'font-weight': ['bold', '700'], }, }, }, to: this.tagName, }, { from: 'b', to: this.tagName, }, ]; }
hedeqiang/am-editor
plugins/bold/src/index.ts
TypeScript
MethodDeclaration
destroy(): void { this.editor.off(MARKDOWN_IT, this.markdownIt); }
hedeqiang/am-editor
plugins/bold/src/index.ts
TypeScript
ArrowFunction
(basePath, cb) => { fs.readdir(basePath, (err, files) => { if (err) return cb(err); async.filter( files, (file, next: (err: boolean) => void) => { fs.stat(path.join(basePath, file), (err, stats) => { return next(!err && stats.isDirectory()); }); }, (dirs) => { return cb(null, dirs); } ); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, files) => { if (err) return cb(err); async.filter( files, (file, next: (err: boolean) => void) => { fs.stat(path.join(basePath, file), (err, stats) => { return next(!err && stats.isDirectory()); }); }, (dirs) => { return cb(null, dirs); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(file, next: (err: boolean) => void) => { fs.stat(path.join(basePath, file), (err, stats) => { return next(!err && stats.isDirectory()); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, stats) => { return next(!err && stats.isDirectory()); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(dirs) => { return cb(null, dirs); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(done) => { _readDirectories(this.templatePath, (err, res) => { this.availableLanguages = res; done(err); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, res) => { this.availableLanguages = res; done(err); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(done) => { if (opts.storage) { this.storage = opts.storage; done(); } else { this.storage = new Storage(); this.storage.connect( opts.storageOpts, done ); } }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(done) => { this.messageBroker = opts.messageBroker || new MessageBroker(opts.messageBrokerOpts); this.messageBroker.onMessage( _.bind(this._sendPushNotifications, this) ); done(); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err) => { if (err) { log.error(err); } return cb(err); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, should) => { if (err) return cb(err); log.debug('Should send notification: ', should); if (!should) return cb(); this._getRecipientsList(notification, notifType, ( err, recipientsList ) => { if (err) return cb(err); async.waterfall( [ (next) => { this._readAndApplyTemplates( notification, notifType, recipientsList, next ); }, (contents, next) => { async.map( recipientsList, (recipient: IPreferences, next) => { const content = contents[recipient.language]; this.storage.fetchPushNotificationSubs( recipient.copayerId, (err, subs) => { if (err) return next(err); const notifications = _.map(subs, (sub) => { return { to: sub.token, priority: 'high', restricted_package_name: sub.packageName, notification: { title: content.plain.subject, body: content.plain.body, sound: 'default', click_action: 'FCM_PLUGIN_ACTIVITY', icon: 'fcm_push_icon' }, data: { walletId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(notification.walletId) ), copayerId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(recipient.copayerId) ), title: content.plain.subject, body: content.plain.body, notification_type: notification.type } }; }); return next(err, notifications); } ); }, (err, allNotifications) => { if (err) return next(err); return next(null, _.flatten(allNotifications)); } ); }, (notifications, next) => { async.each( notifications, (notification, next) => { this._makeRequest(notification, (err, response) => { if (err) log.error(err); if (response) { log.debug('Request status: ', response.statusCode); log.debug('Request message: ', response.statusMessage); log.debug('Request body: ', response.request.body); } next(); }); }, (err) => { return next(err); } ); } ], (err) => { if (err) { log.error('An error ocurred generating notification', err); } return cb(err); } ); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
( err, recipientsList ) => { if (err) return cb(err); async.waterfall( [ (next) => { this._readAndApplyTemplates( notification, notifType, recipientsList, next ); }, (contents, next) => { async.map( recipientsList, (recipient: IPreferences, next) => { const content = contents[recipient.language]; this.storage.fetchPushNotificationSubs( recipient.copayerId, (err, subs) => { if (err) return next(err); const notifications = _.map(subs, (sub) => { return { to: sub.token, priority: 'high', restricted_package_name: sub.packageName, notification: { title: content.plain.subject, body: content.plain.body, sound: 'default', click_action: 'FCM_PLUGIN_ACTIVITY', icon: 'fcm_push_icon' }, data: { walletId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(notification.walletId) ), copayerId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(recipient.copayerId) ), title: content.plain.subject, body: content.plain.body, notification_type: notification.type } }; }); return next(err, notifications); } ); }, (err, allNotifications) => { if (err) return next(err); return next(null, _.flatten(allNotifications)); } ); }, (notifications, next) => { async.each( notifications, (notification, next) => { this._makeRequest(notification, (err, response) => { if (err) log.error(err); if (response) { log.debug('Request status: ', response.statusCode); log.debug('Request message: ', response.statusMessage); log.debug('Request body: ', response.request.body); } next(); }); }, (err) => { return next(err); } ); } ], (err) => { if (err) { log.error('An error ocurred generating notification', err); } return cb(err); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(next) => { this._readAndApplyTemplates( notification, notifType, recipientsList, next ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(contents, next) => { async.map( recipientsList, (recipient: IPreferences, next) => { const content = contents[recipient.language]; this.storage.fetchPushNotificationSubs( recipient.copayerId, (err, subs) => { if (err) return next(err); const notifications = _.map(subs, (sub) => { return { to: sub.token, priority: 'high', restricted_package_name: sub.packageName, notification: { title: content.plain.subject, body: content.plain.body, sound: 'default', click_action: 'FCM_PLUGIN_ACTIVITY', icon: 'fcm_push_icon' }, data: { walletId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(notification.walletId) ), copayerId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(recipient.copayerId) ), title: content.plain.subject, body: content.plain.body, notification_type: notification.type } }; }); return next(err, notifications); } ); }, (err, allNotifications) => { if (err) return next(err); return next(null, _.flatten(allNotifications)); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(recipient: IPreferences, next) => { const content = contents[recipient.language]; this.storage.fetchPushNotificationSubs( recipient.copayerId, (err, subs) => { if (err) return next(err); const notifications = _.map(subs, (sub) => { return { to: sub.token, priority: 'high', restricted_package_name: sub.packageName, notification: { title: content.plain.subject, body: content.plain.body, sound: 'default', click_action: 'FCM_PLUGIN_ACTIVITY', icon: 'fcm_push_icon' }, data: { walletId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(notification.walletId) ), copayerId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(recipient.copayerId) ), title: content.plain.subject, body: content.plain.body, notification_type: notification.type } }; }); return next(err, notifications); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, subs) => { if (err) return next(err); const notifications = _.map(subs, (sub) => { return { to: sub.token, priority: 'high', restricted_package_name: sub.packageName, notification: { title: content.plain.subject, body: content.plain.body, sound: 'default', click_action: 'FCM_PLUGIN_ACTIVITY', icon: 'fcm_push_icon' }, data: { walletId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(notification.walletId) ), copayerId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(recipient.copayerId) ), title: content.plain.subject, body: content.plain.body, notification_type: notification.type } }; }); return next(err, notifications); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(sub) => { return { to: sub.token, priority: 'high', restricted_package_name: sub.packageName, notification: { title: content.plain.subject, body: content.plain.body, sound: 'default', click_action: 'FCM_PLUGIN_ACTIVITY', icon: 'fcm_push_icon' }, data: { walletId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(notification.walletId) ), copayerId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(recipient.copayerId) ), title: content.plain.subject, body: content.plain.body, notification_type: notification.type } }; }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, allNotifications) => { if (err) return next(err); return next(null, _.flatten(allNotifications)); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(notifications, next) => { async.each( notifications, (notification, next) => { this._makeRequest(notification, (err, response) => { if (err) log.error(err); if (response) { log.debug('Request status: ', response.statusCode); log.debug('Request message: ', response.statusMessage); log.debug('Request body: ', response.request.body); } next(); }); }, (err) => { return next(err); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(notification, next) => { this._makeRequest(notification, (err, response) => { if (err) log.error(err); if (response) { log.debug('Request status: ', response.statusCode); log.debug('Request message: ', response.statusMessage); log.debug('Request body: ', response.request.body); } next(); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, response) => { if (err) log.error(err); if (response) { log.debug('Request status: ', response.statusCode); log.debug('Request message: ', response.statusMessage); log.debug('Request body: ', response.request.body); } next(); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err) => { return next(err); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err) => { if (err) { log.error('An error ocurred generating notification', err); } return cb(err); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, wallet) => { return cb(err, wallet && wallet.m > 1); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, wallet) => { if (err) return cb(err); let unit; if (wallet.coin != Defaults.COIN) { unit = wallet.coin; } this.storage.fetchPreferences(notification.walletId, null, ( err, preferences ) => { if (err) log.error(err); if (_.isEmpty(preferences)) preferences = []; const recipientPreferences = _.compact( _.map(preferences, (p) => { if (!_.includes(this.availableLanguages, p.language)) { if (p.language) log.warn( 'Language for notifications "' + p.language + '" not available.' ); p.language = this.defaultLanguage; } return { copayerId: p.copayerId, language: p.language, unit: unit || p.unit || this.defaultUnit }; }) ); const copayers = _.keyBy(recipientPreferences, 'copayerId'); const recipientsList = _.compact( _.map(wallet.copayers, (copayer) => { if ( (copayer.id == notification.creatorId && notificationType.notifyCreatorOnly) || (copayer.id != notification.creatorId && !notificationType.notifyCreatorOnly) ) { const p = copayers[copayer.id] || { language: this.defaultLanguage, unit: this.defaultUnit }; return { copayerId: copayer.id, language: p.language || this.defaultLanguage, unit: unit || p.unit || this.defaultUnit }; } }) ); return cb(null, recipientsList); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
( err, preferences ) => { if (err) log.error(err); if (_.isEmpty(preferences)) preferences = []; const recipientPreferences = _.compact( _.map(preferences, (p) => { if (!_.includes(this.availableLanguages, p.language)) { if (p.language) log.warn( 'Language for notifications "' + p.language + '" not available.' ); p.language = this.defaultLanguage; } return { copayerId: p.copayerId, language: p.language, unit: unit || p.unit || this.defaultUnit }; }) ); const copayers = _.keyBy(recipientPreferences, 'copayerId'); const recipientsList = _.compact( _.map(wallet.copayers, (copayer) => { if ( (copayer.id == notification.creatorId && notificationType.notifyCreatorOnly) || (copayer.id != notification.creatorId && !notificationType.notifyCreatorOnly) ) { const p = copayers[copayer.id] || { language: this.defaultLanguage, unit: this.defaultUnit }; return { copayerId: copayer.id, language: p.language || this.defaultLanguage, unit: unit || p.unit || this.defaultUnit }; } }) ); return cb(null, recipientsList); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(p) => { if (!_.includes(this.availableLanguages, p.language)) { if (p.language) log.warn( 'Language for notifications "' + p.language + '" not available.' ); p.language = this.defaultLanguage; } return { copayerId: p.copayerId, language: p.language, unit: unit || p.unit || this.defaultUnit }; }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(copayer) => { if ( (copayer.id == notification.creatorId && notificationType.notifyCreatorOnly) || (copayer.id != notification.creatorId && !notificationType.notifyCreatorOnly) ) { const p = copayers[copayer.id] || { language: this.defaultLanguage, unit: this.defaultUnit }; return { copayerId: copayer.id, language: p.language || this.defaultLanguage, unit: unit || p.unit || this.defaultUnit }; } }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(recipient: { language: string }, next) => { async.waterfall( [ (next) => { this._getDataForTemplate(notification, recipient, next); }, (data, next) => { async.map( ['plain', 'html'], (type, next) => { this._loadTemplate(notifType, recipient, '.' + type, ( err, template ) => { if (err && type == 'html') return next(); if (err) return next(err); this._applyTemplate(template, data, (err, res) => { return next(err, [type, res]); }); }); }, (err, res) => { return next( err, _.fromPairs(res.filter(Boolean) as any[]) ); } ); }, (result, next) => { next(null, result); } ], (err, res) => { next(err, [recipient.language, res]); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(next) => { this._getDataForTemplate(notification, recipient, next); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(data, next) => { async.map( ['plain', 'html'], (type, next) => { this._loadTemplate(notifType, recipient, '.' + type, ( err, template ) => { if (err && type == 'html') return next(); if (err) return next(err); this._applyTemplate(template, data, (err, res) => { return next(err, [type, res]); }); }); }, (err, res) => { return next( err, _.fromPairs(res.filter(Boolean) as any[]) ); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(type, next) => { this._loadTemplate(notifType, recipient, '.' + type, ( err, template ) => { if (err && type == 'html') return next(); if (err) return next(err); this._applyTemplate(template, data, (err, res) => { return next(err, [type, res]); }); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
( err, template ) => { if (err && type == 'html') return next(); if (err) return next(err); this._applyTemplate(template, data, (err, res) => { return next(err, [type, res]); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, res) => { return next(err, [type, res]); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, res) => { return next( err, _.fromPairs(res.filter(Boolean) as any[]) ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(result, next) => { next(null, result); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, res) => { next(err, [recipient.language, res]); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, res) => { return cb(err, _.fromPairs(res.filter(Boolean) as any[])); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, wallet) => { if (err || !wallet) return cb(err); data.walletId = wallet.id; data.walletName = wallet.name; data.walletM = wallet.m; data.walletN = wallet.n; const copayer = wallet.copayers.find( (c) => c.id === notification.creatorId ); /* *var copayer = _.find(wallet.copayers, { * id: notification.creatorId *}); */ if (copayer) { data.copayerId = copayer.id; data.copayerName = copayer.name; } if (notification.type == 'TxProposalFinallyRejected' && data.rejectedBy) { const rejectors = _.map(data.rejectedBy, (copayerId) => { return wallet.copayers.find((c) => c.id === copayerId).name; }); data.rejectorsNames = rejectors.join(', '); } return cb(null, data); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(c) => c.id === notification.creatorId
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(copayerId) => { return wallet.copayers.find((c) => c.id === copayerId).name; }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(c) => c.id === copayerId
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(t) => { try { return Mustache.render(t, data); } catch (e) { log.error('Could not apply data to template', e); error = e; } }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, template) => { if (err) return cb(err); return cb(null, this._compileTemplate(template, extension)); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
ArrowFunction
(err, template) => { if (err) { return cb( new Error('Could not read template file ' + fullFilename + err) ); } return cb(null, template); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
InterfaceDeclaration
export interface IPushNotificationService { templatePath: string; defaultLanguage: string; defaultUnit: string; subjectPrefix: string; pushServerUrl: string; availableLanguages: string; authorizationKey: string; messageBroker: any; }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
start(opts, cb) { opts = opts || {}; this.request = opts.request || defaultRequest; const _readDirectories = (basePath, cb) => { fs.readdir(basePath, (err, files) => { if (err) return cb(err); async.filter( files, (file, next: (err: boolean) => void) => { fs.stat(path.join(basePath, file), (err, stats) => { return next(!err && stats.isDirectory()); }); }, (dirs) => { return cb(null, dirs); } ); }); }; this.templatePath = path.normalize( (opts.pushNotificationsOpts.templatePath || __dirname + '../../templates') + '/' ); this.defaultLanguage = opts.pushNotificationsOpts.defaultLanguage || 'en'; this.defaultUnit = opts.pushNotificationsOpts.defaultUnit || 'btc'; this.subjectPrefix = opts.pushNotificationsOpts.subjectPrefix || ''; this.pushServerUrl = opts.pushNotificationsOpts.pushServerUrl; this.authorizationKey = opts.pushNotificationsOpts.authorizationKey; if (!this.authorizationKey) return cb( new Error('Missing authorizationKey attribute in configuration.') ); async.parallel( [ (done) => { _readDirectories(this.templatePath, (err, res) => { this.availableLanguages = res; done(err); }); }, (done) => { if (opts.storage) { this.storage = opts.storage; done(); } else { this.storage = new Storage(); this.storage.connect( opts.storageOpts, done ); } }, (done) => { this.messageBroker = opts.messageBroker || new MessageBroker(opts.messageBrokerOpts); this.messageBroker.onMessage( _.bind(this._sendPushNotifications, this) ); done(); } ], (err) => { if (err) { log.error(err); } return cb(err); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_sendPushNotifications(notification, cb) { cb = cb || function() { }; const notifType = PUSHNOTIFICATIONS_TYPES[notification.type]; if (!notifType) return cb(); log.debug('Notification received: ' + notification.type); log.debug(JSON.stringify(notification)); this._checkShouldSendNotif(notification, (err, should) => { if (err) return cb(err); log.debug('Should send notification: ', should); if (!should) return cb(); this._getRecipientsList(notification, notifType, ( err, recipientsList ) => { if (err) return cb(err); async.waterfall( [ (next) => { this._readAndApplyTemplates( notification, notifType, recipientsList, next ); }, (contents, next) => { async.map( recipientsList, (recipient: IPreferences, next) => { const content = contents[recipient.language]; this.storage.fetchPushNotificationSubs( recipient.copayerId, (err, subs) => { if (err) return next(err); const notifications = _.map(subs, (sub) => { return { to: sub.token, priority: 'high', restricted_package_name: sub.packageName, notification: { title: content.plain.subject, body: content.plain.body, sound: 'default', click_action: 'FCM_PLUGIN_ACTIVITY', icon: 'fcm_push_icon' }, data: { walletId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(notification.walletId) ), copayerId: sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash(recipient.copayerId) ), title: content.plain.subject, body: content.plain.body, notification_type: notification.type } }; }); return next(err, notifications); } ); }, (err, allNotifications) => { if (err) return next(err); return next(null, _.flatten(allNotifications)); } ); }, (notifications, next) => { async.each( notifications, (notification, next) => { this._makeRequest(notification, (err, response) => { if (err) log.error(err); if (response) { log.debug('Request status: ', response.statusCode); log.debug('Request message: ', response.statusMessage); log.debug('Request body: ', response.request.body); } next(); }); }, (err) => { return next(err); } ); } ], (err) => { if (err) { log.error('An error ocurred generating notification', err); } return cb(err); } ); }); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_checkShouldSendNotif(notification, cb) { if (notification.type != 'NewTxProposal') return cb(null, true); this.storage.fetchWallet(notification.walletId, (err, wallet) => { return cb(err, wallet && wallet.m > 1); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_getRecipientsList(notification, notificationType, cb) { this.storage.fetchWallet(notification.walletId, (err, wallet) => { if (err) return cb(err); let unit; if (wallet.coin != Defaults.COIN) { unit = wallet.coin; } this.storage.fetchPreferences(notification.walletId, null, ( err, preferences ) => { if (err) log.error(err); if (_.isEmpty(preferences)) preferences = []; const recipientPreferences = _.compact( _.map(preferences, (p) => { if (!_.includes(this.availableLanguages, p.language)) { if (p.language) log.warn( 'Language for notifications "' + p.language + '" not available.' ); p.language = this.defaultLanguage; } return { copayerId: p.copayerId, language: p.language, unit: unit || p.unit || this.defaultUnit }; }) ); const copayers = _.keyBy(recipientPreferences, 'copayerId'); const recipientsList = _.compact( _.map(wallet.copayers, (copayer) => { if ( (copayer.id == notification.creatorId && notificationType.notifyCreatorOnly) || (copayer.id != notification.creatorId && !notificationType.notifyCreatorOnly) ) { const p = copayers[copayer.id] || { language: this.defaultLanguage, unit: this.defaultUnit }; return { copayerId: copayer.id, language: p.language || this.defaultLanguage, unit: unit || p.unit || this.defaultUnit }; } }) ); return cb(null, recipientsList); }); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_readAndApplyTemplates(notification, notifType, recipientsList, cb) { async.map( recipientsList, (recipient: { language: string }, next) => { async.waterfall( [ (next) => { this._getDataForTemplate(notification, recipient, next); }, (data, next) => { async.map( ['plain', 'html'], (type, next) => { this._loadTemplate(notifType, recipient, '.' + type, ( err, template ) => { if (err && type == 'html') return next(); if (err) return next(err); this._applyTemplate(template, data, (err, res) => { return next(err, [type, res]); }); }); }, (err, res) => { return next( err, _.fromPairs(res.filter(Boolean) as any[]) ); } ); }, (result, next) => { next(null, result); } ], (err, res) => { next(err, [recipient.language, res]); } ); }, (err, res) => { return cb(err, _.fromPairs(res.filter(Boolean) as any[])); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_getDataForTemplate(notification: INotification, recipient, cb) { const UNIT_LABELS = { btc: 'BTC', bit: 'bits', dvt: 'DVT' }; const data = _.cloneDeep(notification.data); data.subjectPrefix = _.trim(this.subjectPrefix + ' '); if (data.amount) { try { const unit = recipient.unit.toLowerCase(); data.amount = Utils.formatAmount(+data.amount, unit) + ' ' + UNIT_LABELS[unit]; } catch (ex) { return cb(new Error('Could not format amount' + ex)); } } this.storage.fetchWallet(notification.walletId, (err, wallet) => { if (err || !wallet) return cb(err); data.walletId = wallet.id; data.walletName = wallet.name; data.walletM = wallet.m; data.walletN = wallet.n; const copayer = wallet.copayers.find( (c) => c.id === notification.creatorId ); /* *var copayer = _.find(wallet.copayers, { * id: notification.creatorId *}); */ if (copayer) { data.copayerId = copayer.id; data.copayerName = copayer.name; } if (notification.type == 'TxProposalFinallyRejected' && data.rejectedBy) { const rejectors = _.map(data.rejectedBy, (copayerId) => { return wallet.copayers.find((c) => c.id === copayerId).name; }); data.rejectorsNames = rejectors.join(', '); } return cb(null, data); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_applyTemplate(template, data, cb) { if (!data) return cb(new Error('Could not apply template to empty data')); let error; const result = _.mapValues(template, (t) => { try { return Mustache.render(t, data); } catch (e) { log.error('Could not apply data to template', e); error = e; } }); if (error) return cb(error); return cb(null, result); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_loadTemplate(notifType, recipient, extension, cb) { this._readTemplateFile( recipient.language, notifType.filename + extension, (err, template) => { if (err) return cb(err); return cb(null, this._compileTemplate(template, extension)); } ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_readTemplateFile(language, filename, cb) { const fullFilename = path.join(this.templatePath, language, filename); fs.readFile(fullFilename, 'utf8', (err, template) => { if (err) { return cb( new Error('Could not read template file ' + fullFilename + err) ); } return cb(null, template); }); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_compileTemplate(template, extension) { const lines = template.split('\n'); if (extension == '.html') { lines.unshift(''); } return { subject: lines[0], body: _.tail(lines).join('\n') }; }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
MethodDeclaration
_makeRequest(opts, cb) { this.request( { url: this.pushServerUrl + '/send', method: 'POST', json: true, headers: { 'Content-Type': 'application/json', 'Authorization': 'key=' + this.authorizationKey }, body: opts }, cb ); }
devaultcrypto/bitcore-dvt
packages/bitcore-wallet-service/src/lib/pushnotificationsservice.ts
TypeScript
InterfaceDeclaration
export interface GetTelegrafsRequest { /** The organization ID the Telegraf config belongs to. */ orgID?: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface PostTelegrafsRequest { /** Telegraf config to create */ body: TelegrafRequest }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface GetTelegrafsIDRequest { /** The Telegraf config ID. */ telegrafID: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface PutTelegrafsIDRequest { /** The Telegraf config ID. */ telegrafID: string /** Telegraf config update to apply */ body: TelegrafRequest }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface DeleteTelegrafsIDRequest { /** The Telegraf config ID. */ telegrafID: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface GetTelegrafsIDLabelsRequest { /** The Telegraf config ID. */ telegrafID: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface PostTelegrafsIDLabelsRequest { /** The Telegraf config ID. */ telegrafID: string /** Label to add */ body: LabelMapping }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface DeleteTelegrafsIDLabelsIDRequest { /** The Telegraf config ID. */ telegrafID: string /** The label ID. */ labelID: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface GetTelegrafsIDMembersRequest { /** The Telegraf config ID. */ telegrafID: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface PostTelegrafsIDMembersRequest { /** The Telegraf config ID. */ telegrafID: string /** User to add as member */ body: AddResourceMemberRequestBody }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface DeleteTelegrafsIDMembersIDRequest { /** The ID of the member to remove. */ userID: string /** The Telegraf config ID. */ telegrafID: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript
InterfaceDeclaration
export interface GetTelegrafsIDOwnersRequest { /** The Telegraf config ID. */ telegrafID: string }
JungDonggun/influxdb-client-js
packages/apis/src/generated/TelegrafsAPI.ts
TypeScript