Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
NOTIFICATION_STATUS_COLLECTION_NAME,
NotificationStatusModel
} from "io-functions-commons/dist/src/models/notification_status";
import { TelemetryClient } from "io-functions-commons/dist/src/utils/application_insights";
import {
diffInMilliseconds,
wrapCustomTelemetryClient
} from "io-functions-commons/dist/src/utils/application_insights";
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import * as SendgridTransport from "nodemailer-sendgrid-transport";
// Whether we're in a production environment
const isProduction = process.env.NODE_ENV === "production";
const getCustomTelemetryClient = wrapCustomTelemetryClient(
isProduction,
new TelemetryClient()
);
// Setup DocumentDB
const cosmosDbUri = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_URI");
const cosmosDbKey = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_KEY");
const cosmosDbName = getRequiredStringEnv("COSMOSDB_NAME");
const documentDbDatabaseUrl = documentDbUtils.getDatabaseUri(cosmosDbName);
const notificationsCollectionUrl = documentDbUtils.getCollectionUri(
documentDbDatabaseUrl,
NOTIFICATION_COLLECTION_NAME
);
MessageStatusModel
} from "io-functions-commons/dist/src/models/message_status";
import {
newSenderService,
SENDER_SERVICE_COLLECTION_NAME,
SenderServiceModel
} from "io-functions-commons/dist/src/models/sender_service";
import { wrapCustomTelemetryClient } from "io-functions-commons/dist/src/utils/application_insights";
import { ulidGenerator } from "io-functions-commons/dist/src/utils/strings";
// Whether we're in a production environment
const isProduction = process.env.NODE_ENV === "production";
const getCustomTelemetryClient = wrapCustomTelemetryClient(
isProduction,
new TelemetryClient()
);
// Setup DocumentDB
const cosmosDbUri = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_URI");
const cosmosDbKey = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_KEY");
const cosmosDbName = getRequiredStringEnv("COSMOSDB_NAME");
const documentDbDatabaseUrl = documentDbUtils.getDatabaseUri(cosmosDbName);
const profilesCollectionUrl = documentDbUtils.getCollectionUri(
documentDbDatabaseUrl,
PROFILE_COLLECTION_NAME
);
const messagesCollectionUrl = documentDbUtils.getCollectionUri(
documentDbDatabaseUrl,
const ContextWithBindings = t.exact(
t.interface({
bindings: t.partial({ notificationEvent: t.object })
})
);
type ContextWithBindings = t.TypeOf & Context;
// HTTP external requests timeout in milliseconds
const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
// Whether we're in a production environment
const isProduction = process.env.NODE_ENV === "production";
const getCustomTelemetryClient = wrapCustomTelemetryClient(
isProduction,
new TelemetryClient()
);
// Needed to call notifications API
const publicApiUrl = getRequiredStringEnv("PUBLIC_API_URL");
const publicApiKey = getRequiredStringEnv("PUBLIC_API_KEY");
type WelcomeMessages = ReadonlyArray<(p: ExtendedProfile) => NewMessage>;
// TODO: internal links
// TODO: switch text based on user's preferred_language
const welcomeMessages: WelcomeMessages = [
(_: ExtendedProfile) =>
NewMessage.decode({
content: {
SENDER_SERVICE_COLLECTION_NAME,
SenderServiceModel
} from "io-functions-commons/dist/src/models/sender_service";
import {
GetService,
GetServicesByRecipient,
GetVisibleServices
} from "./controllers/services";
import { TelemetryClient } from "io-functions-commons/dist/src/utils/application_insights";
import { wrapCustomTelemetryClient } from "io-functions-commons/dist/src/utils/application_insights";
// Whether we're in a production environment
const isProduction = process.env.NODE_ENV === "production";
const getCustomTelemetryClient = wrapCustomTelemetryClient(
isProduction,
new TelemetryClient()
);
// Setup Express
const app = express();
secureExpressApp(app);
// Set up CORS (free access to the API from browser clients)
app.use(cors());
// Setup DocumentDB
const cosmosDbUri = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_URI");
const cosmosDbKey = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_KEY");
const cosmosDbName = getRequiredStringEnv("COSMOSDB_NAME");
import { TelemetryClient } from "io-functions-commons/dist/src/utils/application_insights";
import {
diffInMilliseconds,
wrapCustomTelemetryClient
} from "io-functions-commons/dist/src/utils/application_insights";
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import { UrlFromString } from "italia-ts-commons/lib/url";
import { CreatedMessageWithContent } from "./api/definitions/CreatedMessageWithContent";
import { HttpsUrl } from "./api/definitions/HttpsUrl";
import { MessageContent } from "./api/definitions/MessageContent";
import { SenderMetadata } from "./api/definitions/SenderMetadata";
// Whether we're in a production environment
const isProduction = process.env.NODE_ENV === "production";
const getCustomTelemetryClient = wrapCustomTelemetryClient(
isProduction,
new TelemetryClient()
);
// Setup DocumentDB
const cosmosDbUri = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_URI");
const cosmosDbKey = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_KEY");
const cosmosDbName = getRequiredStringEnv("COSMOSDB_NAME");
const documentDbDatabaseUrl = documentDbUtils.getDatabaseUri(cosmosDbName);
const notificationsCollectionUrl = documentDbUtils.getCollectionUri(
documentDbDatabaseUrl,
NOTIFICATION_COLLECTION_NAME
);