本文整理匯總了TypeScript中logspect.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: next
handler: async function (req, res, next) {
const model: Requests.Authorize = req.validatedBody;
let user: User;
try {
user = await UserDb.get(req.user._id);
} catch (e) {
inspect(`Error getting user ${req.user._id} from database.`, e);
return next(e);
}
const accessToken = await Auth.authorize(model.code, model.shop, Constants.SHOPIFY_API_KEY, Constants.SHOPIFY_SECRET_KEY);
// Store the user's shop data
user.shopify_domain = model.shop;
user.shopify_access_token = accessToken;
user.permissions = Constants.DEFAULT_SCOPES;
try {
const shop = await new Shops(model.shop, accessToken).get({ fields: "name,id" });
user.shopify_shop_name = shop.name;
user.shopify_shop_id = shop.id;
} catch (e) {
inspect(`Failed to get shop data from ${model.shop}`, e);
}
try {
const updateResult = await UserDb.put(user._id, user, user._rev);
user._rev = updateResult.rev;
} catch (e) {
inspect(`Failed to update user ${user._id}'s Shopify access token`, e);
return next(e);
}
await res.withSessionToken(user);
// Don't create any webhooks unless this app is running on a real domain. Webhooks cannot point to localhost.
if (Constants.ISLIVE) {
// Create the AppUninstalled webhook immediately after the user accepts installation
const webhooks = new Webhooks(model.shop, accessToken);
const existingHooks = await webhooks.list({ topic: "app/uninstalled", fields: "id", limit: 1 });
// Ensure the webhook doesn't already exist
if (existingHooks.length === 0) {
const hook = await webhooks.create({
address: req.domainWithProtocol + Paths.api.webhooks.base + `app-uninstalled?shop_id=${user.shopify_shop_id}`,
topic: "app/uninstalled"
})
}
}
return next();
}
示例2: next
handler: async function (req, res, next) {
const model: Requests.CreateSession = req.validatedBody;
let user: User;
try {
user = await UserDb.get(model.username.toLowerCase());
} catch (e) {
const err: boom.BoomError = e;
if (err.isBoom && err.output.statusCode !== 404) {
return next(e);
}
}
if (!user || !compareSync(model.password, user.hashed_password)) {
return next(boom.unauthorized("No user found with that username or password combination."));
}
// The user has logged in again, so we'll remove their user id from the auth-invalidation cache.
try {
await Cache.deleteValue(CACHE_SEGMENT_AUTH, user._id);
} catch (e) {
inspect(`Failed to remove user ${user._id} from auth-invalidation cache.`, e);
}
res = await res.withSessionToken(user);
return next();
}
示例3: next
handler: async function (req, res, next) {
const payload: Requests.UpdatePassword = req.validatedBody;
let user = await UserDb.get(req.user._id);
// Ensure the user's current password is correct
if (!compareSync(payload.old_password, user.hashed_password)) {
return next(boom.forbidden(`Your current password is incorrect.`));
}
// Change the user's password
user.hashed_password = hashSync(payload.new_password);
try {
const updateResult = await UserDb.put(user._id, user, user._rev);
user._rev = updateResult.rev
} catch (e) {
inspect("Failed to update user's password.", e);
return next(e);
}
await res.withSessionToken(user);
return next();
}
示例4: next
handler: async function (req, res, next) {
const query: Requests.AppUninstalled = req.query;
const userSearch = await UserDb.find({
selector: {
shopify_shop_id: {
$eq: parseInt(query.shop_id)
}
}
});
if (userSearch.length === 0) {
inspect(`Could not find owner of shop id ${query.shop_id} during app/uninstalled webhook. Returning true to prevent webhook retries.`);
// No user found with that shopId. This webhook may be a duplicate. Return OK to prevent Shopify resending the webhook.
res.status(200);
return next();
}
const user = userSearch[0];
// Shopify access token has already been invalidated at this point. Remove the user's Shopify data.
user.shopify_access_token = undefined;
user.shopify_domain = undefined;
user.shopify_shop_id = undefined;
user.shopify_shop_name = undefined;
user.charge_id = undefined;
user.plan_id = undefined;
const update = await UserDb.put(user._id, user, user._rev);
// Add the user's id to the auth-invalidation cache, forcing their next request to prompt them to login again.
try {
await Cache.setValue(CACHE_SEGMENT_AUTH, user._id, true, 21 * 1000 * 60 * 60 * 24 /* 21 days in milliseconds */);
}
catch (e) {
inspect("Failed to delete user data from auth cache after handling app/uninstalled webhook.", e);
}
res.json({});
return next();
}
示例5: next
app.use(function (err: Error | BoomError, req: express.Request, res: express.Response, next: Function) {
const fullError = isBoomError(err) ? err : wrap(err);
if (fullError.output.statusCode >= 500) {
inspect(`Error in ${req.url}`, err);
}
res.status(fullError.output.statusCode).json(fullError.output.payload);
return next();
});
示例6: catch
userAuthIsValid: async user => {
// If user id exists in invalidation cache, return a 401 unauthed response.
try {
const cacheValue = await Cache.getValue(Constants.CACHE_SEGMENT_AUTH, user._id);
if (!!cacheValue) {
return false;
}
} catch (e) {
inspect(`Error attempting to retrieve ${user._id} value from auth-invalidation cache.`, e);
return false;
}
return true;
},
示例7: inspect
}).catch(e => {
inspect("Error starting server.", e);
});