@salutejs/scenario
Advanced tools
Comparing version 0.12.0-canary.200.85ea4c7724458b276bdbd1c2434a785048d80125.0 to 0.12.0-canary.200.bd6f65ebcf53b228a181f872b01f081da0d8e15c.0
@@ -1,6 +0,8 @@ | ||
import { DeliveryConfig, SmartPushResponse } from './types/push'; | ||
import { DeliveryConfig, Destination, SmartPushResponse } from './types/push'; | ||
export interface SendPushConfiguration { | ||
projectId: string; | ||
clientIdSub: string; | ||
deliveryConfig: DeliveryConfig; | ||
deliveryConfig: { | ||
destinations: Omit<Destination, 'channel'>[]; | ||
} & Omit<DeliveryConfig, 'destinations'>; | ||
} | ||
@@ -10,5 +12,3 @@ export declare const createSmartPushSender: ({ clientId, secret }?: { | ||
secret: string; | ||
}) => Promise<{ | ||
send: (push: SendPushConfiguration) => Promise<SmartPushResponse>; | ||
}>; | ||
}) => Promise<(push: SendPushConfiguration) => Promise<SmartPushResponse>>; | ||
//# sourceMappingURL=smartpush.d.ts.map |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -38,2 +49,13 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -75,6 +97,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var body, answer; | ||
var destinations, delivery, body, answer; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
destinations = deliveryConfig.destinations, delivery = __rest(deliveryConfig, ["destinations"]); | ||
body = { | ||
@@ -94,3 +117,6 @@ protocolVersion: 'V1', | ||
}, | ||
deliveryConfig: deliveryConfig, | ||
deliveryConfig: __assign(__assign({}, delivery), { destinations: destinations.map(function (_a) { | ||
var surface = _a.surface, destination = __rest(_a, ["surface"]); | ||
return (__assign(__assign({}, destination), { surface: surface, channel: surface === 'COMPANION' ? 'COMPANION_B2C' : 'B2C' })); | ||
}) }), | ||
}, | ||
@@ -140,5 +166,3 @@ }; | ||
messageId = 0; | ||
return [2 /*return*/, { | ||
send: function (push) { return sendPush(access_token, uuidv4(), ++messageId, push); }, | ||
}]; | ||
return [2 /*return*/, function (push) { return sendPush(access_token, uuidv4(), ++messageId, push); }]; | ||
} | ||
@@ -145,0 +169,0 @@ }); |
{ | ||
"name": "@salutejs/scenario", | ||
"version": "0.12.0-canary.200.85ea4c7724458b276bdbd1c2434a785048d80125.0", | ||
"version": "0.12.0-canary.200.bd6f65ebcf53b228a181f872b01f081da0d8e15c.0", | ||
"description": "Tiny helpers to make scenario for Salute family", | ||
@@ -39,3 +39,3 @@ "author": "SberDevices Frontend Team <sberdevices.frontend@gmail.com>", | ||
}, | ||
"gitHead": "85ea4c7724458b276bdbd1c2434a785048d80125" | ||
"gitHead": "bd6f65ebcf53b228a181f872b01f081da0d8e15c" | ||
} |
@@ -152,3 +152,3 @@ # @salutejs/scenario | ||
```ts | ||
import { createSmartPushSender, SendPushConfiguration } from 'salutejs/scenario'; | ||
import { createSmartPushSender, SendPushConfiguration, SmartPushResponse } from 'salutejs/scenario'; | ||
@@ -162,4 +162,3 @@ const pushes: SendPushConfiguration[] = [{ | ||
{ | ||
channel: 'COMPANION_B2C', // Канал Сбер Салют, всегда B2C и только с поверхностью COMPANION - COMPANION_B2C | ||
surface: 'COMPANION', // поверхность Сбер Салют | ||
surface: 'COMPANION', // поверхность (Сбер салют) | ||
templateContent: { | ||
@@ -174,5 +173,5 @@ id: '', // id шаблона уведомления из студии | ||
}]; | ||
const sender = await createSmartPushSender(); | ||
pushes.map((push) => | ||
sender.send(push).then(({ payload }) => { | ||
const sendPush = await createSmartPushSender(); | ||
pushes.forEach((push) => | ||
sendPush(push).then(({ payload }: SmartPushResponse) => { | ||
if (payload.validation.results.some(({ status }) => status.code !== 0)) { | ||
@@ -179,0 +178,0 @@ throw new Error('Уведомление не отправлено'); |
Sorry, the diff of this file is not supported yet
304515
3822
293