How to use ms - 10 common examples

To help you get started, we’ve selected a few ms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / now / packages / now-cli / src / commands / billing / index.js View on Github external
try {
        cards = await creditCards.ls();
      } catch (err) {
        console.error(error(err.message));
        return 1;
      }

      if (cards.sources.length === 0) {
        console.error(error('You have no credit cards to choose from'));
        return 0;
      }

      let cardId = args[0];

      if (cardId === undefined) {
        const elapsed = ms(new Date() - start);
        const message = `Selecting a new default payment card for ${chalk.bold(
          contextName
        )} ${chalk.gray(`[${elapsed}]`)}`;
        const choices = buildInquirerChoices(cards);

        cardId = await listInput({
          message,
          choices,
          separator: true,
          abort: 'end'
        });
      }

      // Check if the provided cardId (in case the user
      // typed `now billing set-default `) is valid
      if (cardId) {
github u-wave / core / src / plugins / booth.js View on Github external
async onStart() {
    this.locker = new RedLock([this.uw.redis]);

    const current = await this.getCurrentEntry();
    if (current && this.timeout === null) {
      // Restart the advance timer after a server restart, if a track was
      // playing before the server restarted.
      const duration = (current.media.end - current.media.start) * ms('1 second');
      const endTime = Number(current.playedAt) + duration;
      if (endTime > Date.now()) {
        this.timeout = setTimeout(
          () => this.advance(),
          endTime - Date.now(),
        );
      } else {
        this.advance();
      }
    }
  }
github nusmodifications / nusmods / api / hasura / src / config.ts View on Github external
hasuraUrl: process.env.HASURA_URL as string,
  mailApiKey: process.env.SENDGRID_API_KEY as string,
  mailAddress: 'noreply@nusmods.com',
  // Passcode for verifying accounts
  passcode: {
    verifyTimeout: ms('15m'),
    verifyLimit: 20,
    requestLimitResetTimeout: ms('5m'),
    requestLimit: 20,
  },
  // Access Token for obtaining information (aka Hasura Token)
  accessToken: {
    nameSpace: hasuraConfig.claims_namespace,
    secretKey: hasuraConfig.key,
    secretAlgorithm: hasuraConfig.type,
    lifeTime: ms('1d'),
  },
  // Refresh Token for obtaining Access Token (aka Long Lived Token)
  refreshToken: {
    secretKey: hasuraConfig.key,
    secretAlgorithm: hasuraConfig.type,
    lifeTime: ms('90d'),
  },
};

export default config;
github microsoft / opensource-portal / routes / api / createRepo.ts View on Github external
];
  const properties = {};
  const parameters = bodyOverride || req.body;
  ourFields.forEach((fieldName) => {
    if (parameters[fieldName] !== undefined) {
      properties[fieldName] = parameters[fieldName];
      delete parameters[fieldName];
    }
  });
  const msProperties = {
    onBehalfOf: properties['ms.onBehalfOf'] || req.headers['ms-onbehalfof'],
    justification: properties['ms.justification'] || req.headers['ms-justification'],
    license: properties['ms.license'] || req.headers['ms-license'],
    approvalType: properties['ms.approval'] || req.headers['ms-approval'],
    approvalUrl: properties['ms.approval-url'] || req.headers['ms-approval-url'],
    notify: properties['ms.notify'] || req.headers['ms-notify'],
    teams: properties['ms.teams'] || req.headers['ms-teams'],
    template: properties['ms.template'] || req.headers['ms-template'],
    projectType: properties['ms.project-type'] || req.headers['ms-project-type'],
  };
  // Validate licenses
  let msLicense = msProperties.license;
  if (!msLicense) {
    throw jsonError(new Error('Missing Microsoft license information'), 422);
  }
  msLicense = msLicense.toLowerCase();
  if (supportedLicenseExpressions.indexOf(msLicense) < 0) {
    throw jsonError(new Error('The provided license expression is not currently supported'), 422);
  }
  // Validate approval types
  const msApprovalType = msProperties.approvalType;
  if (!msApprovalType) {
github microsoft / opensource-portal / routes / api / client / newOrgRepo.ts View on Github external
// Team permissions
  if (!body.selectedAdminTeams || !body.selectedAdminTeams.length) {
    return next(jsonError('No administration team(s) provided in the request', 400));
  }
  translateTeams(body);
  // Initial repo contents and license
  const templates = _.keyBy(organization.getRepositoryCreateMetadata().templates, 'id');
  const template = templates[body.template];
  if (!template) {
    return next(jsonError('There was a configuration problem, the template metadata was not available for this request', 400));
  }
  translateValue(body, 'template', 'ms.template');
  body['ms.license'] = template.spdx || template.name; // Today this is the "template name" or SPDX if available
  translateValue(body, 'gitIgnoreTemplate', 'gitignore_template');
  if (!body['ms.notify']) {
    body['ms.notify'] = req.knownRequesterMailAddress || config.brand.operationsMail || config.brand.supportMail;
  }
  // these fields are currently ignored: orgName
  delete body.orgName;
  delete body.claEntity; // a legacy value
  req.app.settings.providers.insights.trackEvent({
    name: 'ApiClientNewOrgRepoStart',
    properties: {
      body: JSON.stringify(req.body),
    },
  });
  let success: ICreateRepositoryApiResult = null;
  try {
    success = await CreateRepository(req, body);
  } catch (createRepositoryError) {
    req.app.settings.providers.insights.trackEvent({
      name: 'ApiClientNewOrgRepoError',
github microsoft / opensource-portal / routes / api / client / newOrgRepo.ts View on Github external
translateValue(body, 'projectType', 'ms.project-type');
  // Team permissions
  if (!body.selectedAdminTeams || !body.selectedAdminTeams.length) {
    return next(jsonError('No administration team(s) provided in the request', 400));
  }
  translateTeams(body);
  // Initial repo contents and license
  const templates = _.keyBy(organization.getRepositoryCreateMetadata().templates, 'id');
  const template = templates[body.template];
  if (!template) {
    return next(jsonError('There was a configuration problem, the template metadata was not available for this request', 400));
  }
  translateValue(body, 'template', 'ms.template');
  body['ms.license'] = template.spdx || template.name; // Today this is the "template name" or SPDX if available
  translateValue(body, 'gitIgnoreTemplate', 'gitignore_template');
  if (!body['ms.notify']) {
    body['ms.notify'] = req.knownRequesterMailAddress || config.brand.operationsMail || config.brand.supportMail;
  }
  // these fields are currently ignored: orgName
  delete body.orgName;
  delete body.claEntity; // a legacy value
  req.app.settings.providers.insights.trackEvent({
    name: 'ApiClientNewOrgRepoStart',
    properties: {
      body: JSON.stringify(req.body),
    },
  });
  let success: ICreateRepositoryApiResult = null;
  try {
    success = await CreateRepository(req, body);
  } catch (createRepositoryError) {
    req.app.settings.providers.insights.trackEvent({
github microsoft / opensource-portal / routes / api / createRepo.ts View on Github external
const properties = {};
  const parameters = bodyOverride || req.body;
  ourFields.forEach((fieldName) => {
    if (parameters[fieldName] !== undefined) {
      properties[fieldName] = parameters[fieldName];
      delete parameters[fieldName];
    }
  });
  const msProperties = {
    onBehalfOf: properties['ms.onBehalfOf'] || req.headers['ms-onbehalfof'],
    justification: properties['ms.justification'] || req.headers['ms-justification'],
    license: properties['ms.license'] || req.headers['ms-license'],
    approvalType: properties['ms.approval'] || req.headers['ms-approval'],
    approvalUrl: properties['ms.approval-url'] || req.headers['ms-approval-url'],
    notify: properties['ms.notify'] || req.headers['ms-notify'],
    teams: properties['ms.teams'] || req.headers['ms-teams'],
    template: properties['ms.template'] || req.headers['ms-template'],
    projectType: properties['ms.project-type'] || req.headers['ms-project-type'],
  };
  // Validate licenses
  let msLicense = msProperties.license;
  if (!msLicense) {
    throw jsonError(new Error('Missing Microsoft license information'), 422);
  }
  msLicense = msLicense.toLowerCase();
  if (supportedLicenseExpressions.indexOf(msLicense) < 0) {
    throw jsonError(new Error('The provided license expression is not currently supported'), 422);
  }
  // Validate approval types
  const msApprovalType = msProperties.approvalType;
  if (!msApprovalType) {
    throw jsonError(new Error('Missing Microsoft approval type information'), 422);
github microsoft / opensource-portal / routes / api / client / newOrgRepo.ts View on Github external
function translateTeams(body) {
  let admin = body.selectedAdminTeams;
  let write = body.selectedWriteTeams;
  let read = body.selectedReadTeams;

  // Remove teams with higher privileges already
  _.pullAll(write, admin);
  _.pullAll(read, admin);
  _.pullAll(read, write);

  body['ms.teams'] = {
    admin: admin,
    push: write,
    pull: read,
  };

  delete body.selectedAdminTeams;
  delete body.selectedWriteTeams;
  delete body.selectedReadTeams;
}
github microsoft / opensource-portal / routes / api / createRepo.ts View on Github external
'ms.teams',
    'ms.template',
    'ms.project-type',
  ];
  const properties = {};
  const parameters = bodyOverride || req.body;
  ourFields.forEach((fieldName) => {
    if (parameters[fieldName] !== undefined) {
      properties[fieldName] = parameters[fieldName];
      delete parameters[fieldName];
    }
  });
  const msProperties = {
    onBehalfOf: properties['ms.onBehalfOf'] || req.headers['ms-onbehalfof'],
    justification: properties['ms.justification'] || req.headers['ms-justification'],
    license: properties['ms.license'] || req.headers['ms-license'],
    approvalType: properties['ms.approval'] || req.headers['ms-approval'],
    approvalUrl: properties['ms.approval-url'] || req.headers['ms-approval-url'],
    notify: properties['ms.notify'] || req.headers['ms-notify'],
    teams: properties['ms.teams'] || req.headers['ms-teams'],
    template: properties['ms.template'] || req.headers['ms-template'],
    projectType: properties['ms.project-type'] || req.headers['ms-project-type'],
  };
  // Validate licenses
  let msLicense = msProperties.license;
  if (!msLicense) {
    throw jsonError(new Error('Missing Microsoft license information'), 422);
  }
  msLicense = msLicense.toLowerCase();
  if (supportedLicenseExpressions.indexOf(msLicense) < 0) {
    throw jsonError(new Error('The provided license expression is not currently supported'), 422);
  }
github microsoft / opensource-portal / routes / api / client / newOrgRepo.ts View on Github external
translateValue(body, 'justification', 'ms.justification');
  translateValue(body, 'legalEntity', 'ms.entity');
  translateValue(body, 'projectType', 'ms.project-type');
  // Team permissions
  if (!body.selectedAdminTeams || !body.selectedAdminTeams.length) {
    return next(jsonError('No administration team(s) provided in the request', 400));
  }
  translateTeams(body);
  // Initial repo contents and license
  const templates = _.keyBy(organization.getRepositoryCreateMetadata().templates, 'id');
  const template = templates[body.template];
  if (!template) {
    return next(jsonError('There was a configuration problem, the template metadata was not available for this request', 400));
  }
  translateValue(body, 'template', 'ms.template');
  body['ms.license'] = template.spdx || template.name; // Today this is the "template name" or SPDX if available
  translateValue(body, 'gitIgnoreTemplate', 'gitignore_template');
  if (!body['ms.notify']) {
    body['ms.notify'] = req.knownRequesterMailAddress || config.brand.operationsMail || config.brand.supportMail;
  }
  // these fields are currently ignored: orgName
  delete body.orgName;
  delete body.claEntity; // a legacy value
  req.app.settings.providers.insights.trackEvent({
    name: 'ApiClientNewOrgRepoStart',
    properties: {
      body: JSON.stringify(req.body),
    },
  });
  let success: ICreateRepositoryApiResult = null;
  try {
    success = await CreateRepository(req, body);

ms

Tiny millisecond conversion utility

MIT
Latest version published 4 years ago

Package Health Score

76 / 100
Full package analysis