zmp-sdk 2.52.1-beta.1 → 2.52.1-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import n from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import o,{object as e,string as t,number as i}from'./../external/zod/lib/index.mjs.js';import r from"../appEnv/index.js";import a from"../common/notFound.js";import{functionHandler as m}from"../utils/decorator.js";import s from"../common/apis/general/addVoucher.js";import{__generator as l}from'./../external/tslib/tslib.es6.js';var p=e({type:o.enum(["url","phone"]),value:t().min(1),cta:t().min(1)}),c=[e({title:t().min(1).max(200),code:t().min(1).max(140),display:o.enum(["qr_code","bar_code"]).default("qr_code").optional(),name:t().min(1).max(200),desc:t().min(1).max(500).optional(),avatarUrl:t().url().max(500).optional(),partner:t().min(1).optional(),merchantName:t().min(1).max(100),merchantOaId:t().min(1).max(50),merchantLogoUrl:t().url().max(500).optional(),ownerName:t().min(1).max(100),condition:t().min(1).max(500),conditionDetail:t().min(1).max(2e3).optional(),validAt:i().int().nonnegative().optional(),expiredAt:i().int().positive(),remindAt:i().int().nonnegative().optional(),actions:o.array(p).max(3).optional()})];function u(n){return d.apply(this,arguments)}function d(){return d=n((function(o){return l(this,(function(e){return[2,m("addVoucher",c,[o],(t=n((function(n,o){var e;return l(this,(function(t){switch(t.label){case 0:return e=o||n,r.isMp?[4,s(e)]:[3,2];case 1:return[2,t.sent()];case 2:return r.isMpWeb?[2,Promise.resolve()]:[2,Promise.reject(a("addVoucher",{}))]}}))})),function(n,o){return t.apply(this,arguments)}))];var t}))})),d.apply(this,arguments)}export{u as addVoucher};
1
+ import o from'./../external/@swc/helpers/src/_async_to_generator.mjs.js';import n,{object as e,string as t,number as r}from'./../external/zod/lib/index.mjs.js';import i from"../appEnv/index.js";import a from"../common/notFound.js";import{functionHandler as m}from"../utils/decorator.js";import s from"../common/apis/general/addVoucher.js";import{__generator as c}from'./../external/tslib/tslib.es6.js';var p=e({type:n.enum(["url","phone"]),value:t().min(1),cta:t().min(1)}),u=[e({name:t().min(1).max(200),condition:t().min(1).max(500),conditionDetail:t().min(1).max(2e3).optional(),validAt:r().int().nonnegative().optional(),expiredAt:r().int().positive(),code:t().min(1).max(140).optional(),display:n.enum(["qr_code","bar_code"]).default("qr_code").optional(),interactToken:t().min(1).optional(),ownerName:t().min(1).max(100).optional(),merchantOaId:t().min(1).max(50),merchantName:t().min(1).max(100),merchantLogoUrl:t().url().max(500),actions:n.array(p).max(2).optional()})];function l(o){return d.apply(this,arguments)}function d(){return d=o((function(n){return c(this,(function(e){return[2,m("addVoucher",u,[n],(t=o((function(o,n){var e;return c(this,(function(t){switch(t.label){case 0:return e=n||o,i.isMp?[4,s(e)]:[3,2];case 1:return[2,t.sent()];case 2:return i.isMpWeb?[2,Promise.resolve({oa_message_token:""})]:[2,Promise.reject(a("addVoucher",{}))]}}))})),function(o,n){return t.apply(this,arguments)}))];var t}))})),d.apply(this,arguments)}export{l as addVoucher};
@@ -1 +1 @@
1
- import e from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import r from"../../token.js";import{RESPONSE_CODE as n,MESSAGES as t,QRCARD_APIS as o}from"../../../constants.js";import{AppError as a}from"../../../utils/errorHandler.js";import i from"./openWebview.js";import{__generator as s}from'./../../../external/tslib/tslib.es6.js';var c,d=(c=e((function(e){var c,d,l,m,u,p,E;return s(this,(function(s){switch(s.label){case 0:return[4,r.jumpAndGetToken()];case 1:if(s.sent(),!(l=null===(c=r.miniProgramConfig)||void 0===c?void 0:c.jwt))throw new a(n.UNAUTHORIZED,t.LOGIN_REQUIRED);return(m=new URLSearchParams).append("data",JSON.stringify(function(e){return{title:e.title,code:e.code,display:e.display||"qr_code",name:e.name,desc:e.desc||e.ownerName,avatarUrl:e.avatarUrl||e.merchantLogoUrl,partner:e.partner,merchantName:e.merchantName,merchantOaId:e.merchantOaId,merchantLogoUrl:e.merchantLogoUrl,ownerName:e.ownerName,condition:e.condition,conditionDetail:e.conditionDetail,validAt:e.validAt,expiredAt:e.expiredAt,remindAt:e.remindAt,actions:e.actions}}(e))),[4,fetch(o.ADD_VOUCHER,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",authorization:"Bearer ".concat(l)},body:m})];case 2:u=s.sent(),s.label=3;case 3:return s.trys.push([3,5,,6]),[4,u.json()];case 4:return p=s.sent(),[3,6];case 5:throw s.sent(),new a(n.VOUCHER_CREATE_FAILED,t.VOUCHER_CREATE_FAILED);case 6:if(0!==(null==p?void 0:p.err))throw new a("number"==typeof(null==p?void 0:p.err)?p.err:n.VOUCHER_CREATE_FAILED,function(e){var r="string"==typeof(null==e?void 0:e.msg)?e.msg.trim():"";return r||(-1===(null==e?void 0:e.err)?"Unknown exception":t.VOUCHER_CREATE_FAILED)}(p));if(!(E=null===(d=p.data)||void 0===d?void 0:d.deeplink))throw new a(n.VOUCHER_CREATE_FAILED,t.VOUCHER_CREATE_FAILED);return[4,i(E)];case 7:return s.sent(),[2]}}))})),function(e){return c.apply(this,arguments)});export{d as default};
1
+ import e from'./../../../external/@swc/helpers/src/_async_to_generator.mjs.js';import n from"../../token.js";import{RESPONSE_CODE as t,MESSAGES as r,QRCARD_APIS as o}from"../../../constants.js";import{AppError as a}from"../../../utils/errorHandler.js";import i from"./openWebview.js";import{__generator as s}from'./../../../external/tslib/tslib.es6.js';var c,d=(c=e((function(e){var c,d,l,m,u,p,E,_,f;return s(this,(function(s){switch(s.label){case 0:return[4,n.jumpAndGetToken()];case 1:if(s.sent(),!(m=null===(c=n.miniProgramConfig)||void 0===c?void 0:c.jwt))throw new a(t.UNAUTHORIZED,r.LOGIN_REQUIRED);return(u=new URLSearchParams).append("data",JSON.stringify(function(e){return{name:e.name,condition:e.condition,conditionDetail:e.conditionDetail,validAt:e.validAt,expiredAt:e.expiredAt,code:e.code,display:e.display||"qr_code",ownerName:e.ownerName,merchantOaId:e.merchantOaId,merchantName:e.merchantName,merchantLogoUrl:e.merchantLogoUrl,actions:e.actions}}(e))),e.interactToken&&u.append("interactToken",e.interactToken),[4,fetch(o.ADD_VOUCHER,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",authorization:"Bearer ".concat(m)},body:u})];case 2:p=s.sent(),s.label=3;case 3:return s.trys.push([3,5,,6]),[4,p.json()];case 4:return E=s.sent(),[3,6];case 5:throw s.sent(),new a(t.VOUCHER_CREATE_FAILED,r.VOUCHER_CREATE_FAILED);case 6:if(0!==(null==E?void 0:E.err))throw new a("number"==typeof(null==E?void 0:E.err)?E.err:t.VOUCHER_CREATE_FAILED,function(e){var n="string"==typeof(null==e?void 0:e.msg)?e.msg.trim():"";return n||(-1===(null==e?void 0:e.err)?"Unknown exception":r.VOUCHER_CREATE_FAILED)}(E));if(_=null===(d=E.data)||void 0===d?void 0:d.deeplink,f=(null===(l=E.data)||void 0===l?void 0:l.oaMessageToken)||"",!_)throw new a(t.VOUCHER_CREATE_FAILED,r.VOUCHER_CREATE_FAILED);return[4,i(_)];case 7:return s.sent(),[2,{oa_message_token:f}]}}))})),function(e){return c.apply(this,arguments)});export{d as default};
package/apis/index.d.ts CHANGED
@@ -1305,74 +1305,66 @@ type VoucherAction = {
1305
1305
  cta: string;
1306
1306
  };
1307
1307
  type AddVoucherData = {
1308
- /**
1309
- * Tiêu đề hiển thị trên card.
1310
- */
1311
- title: string;
1312
- /**
1313
- * Nội dung encode vào QR hoặc barcode.
1314
- */
1315
- code: string;
1316
- /**
1317
- * Loại mã hiển thị. Mặc định là `qr_code`.
1318
- */
1319
- display?: VoucherDisplayType;
1320
1308
  /**
1321
1309
  * Tên voucher / ưu đãi.
1322
1310
  */
1323
1311
  name: string;
1324
1312
  /**
1325
- * Tên chủ thẻ hiển thị phụ dưới tên voucher. Mặc định dùng `ownerName`.
1313
+ * Điều kiện áp dụng (chính), hiển thị trên chi tiết vé.
1326
1314
  */
1327
- desc?: string;
1315
+ condition: string;
1328
1316
  /**
1329
- * Logo hiển thị trên card. Mặc định dùng `merchantLogoUrl`.
1317
+ * Điều kiện áp dụng chi tiết (phụ).
1330
1318
  */
1331
- avatarUrl?: string;
1319
+ conditionDetail?: string;
1332
1320
  /**
1333
- * Nguồn phát hành voucher.
1321
+ * Thời gian bắt đầu hiệu lực, epoch milliseconds.
1334
1322
  */
1335
- partner?: string;
1323
+ validAt?: number;
1336
1324
  /**
1337
- * Tên thương hiệu / cửa hàng phát hành voucher.
1325
+ * Hạn sử dụng, epoch milliseconds.
1338
1326
  */
1339
- merchantName: string;
1327
+ expiredAt: number;
1340
1328
  /**
1341
- * OA ID của merchant trên Zalo.
1329
+ * Mã voucher; không truyền thì tự sinh QR OA của merchant.
1342
1330
  */
1343
- merchantOaId: string;
1331
+ code?: string;
1344
1332
  /**
1345
- * Logo merchant.
1333
+ * Loại mã hiển thị. Mặc định là `qr_code`.
1346
1334
  */
1347
- merchantLogoUrl?: string;
1335
+ display?: VoucherDisplayType;
1348
1336
  /**
1349
- * Tên người nhận voucher.
1337
+ * Token để merchant gửi tin nhắn không tốn phí. Lấy từ callback
1338
+ * `onDataReceived` của `showFunctionButtonWidget`.
1350
1339
  */
1351
- ownerName: string;
1340
+ interactToken?: string;
1352
1341
  /**
1353
- * Điều kiện sử dụng tóm tắt.
1342
+ * Tên khách hàng sở hữu; không truyền thì không hiển thị trên vé.
1354
1343
  */
1355
- condition: string;
1344
+ ownerName?: string;
1356
1345
  /**
1357
- * Điều kiện sử dụng đầy đủ.
1346
+ * OA ID của merchant trên Zalo.
1358
1347
  */
1359
- conditionDetail?: string;
1348
+ merchantOaId: string;
1360
1349
  /**
1361
- * Thời điểm bắt đầu hiệu lực, epoch milliseconds.
1350
+ * Tên OA / thương hiệu phát hành voucher.
1362
1351
  */
1363
- validAt?: number;
1352
+ merchantName: string;
1364
1353
  /**
1365
- * Thời điểm hết hạn, epoch milliseconds.
1354
+ * Logo OA, dùng làm logo hiển thị trên voucher.
1366
1355
  */
1367
- expiredAt: number;
1356
+ merchantLogoUrl: string;
1368
1357
  /**
1369
- * Thời điểm gửi nhắc hạn, epoch milliseconds.
1358
+ * Danh sách CTA hiển thị trên thẻ (tối đa 2).
1370
1359
  */
1371
- remindAt?: number;
1360
+ actions?: VoucherAction[];
1361
+ };
1362
+ type AddVoucherReturns = {
1372
1363
  /**
1373
- * Danh sách CTA hiển thị trên thẻ.
1364
+ * Token để merchant gửi tin nhắn OA cho người dùng; chuỗi rỗng nếu server
1365
+ * không trả về.
1374
1366
  */
1375
- actions?: VoucherAction[];
1367
+ oa_message_token: string;
1376
1368
  };
1377
1369
  type TempFile = {
1378
1370
  /**
@@ -4955,39 +4947,64 @@ declare function addRating(args?: AsyncVoidCallback): Promise<void>;
4955
4947
  * API này gửi dữ liệu voucher từ Mini App về server trung gian. Server trung gian
4956
4948
  * chịu trách nhiệm đăng nhập Ví QR, mã hoá dữ liệu bằng `secureKey`, sau đó trả về
4957
4949
  * deeplink thêm thẻ vào Ví QR. SDK sẽ tự mở deeplink này bằng `openWebview` để đưa
4958
- * người dùng tới màn hình thêm thẻ; deeplink không được trả về cho bên gọi.
4950
+ * người dùng tới màn hình thêm thẻ; deeplink không được trả về cho bên gọi, chỉ
4951
+ * trả về `oa_message_token`.
4959
4952
  *
4960
4953
  * @zaloOnly Chỉ hoạt động khi chạy bên trong ứng dụng Zalo mobile.
4961
4954
  *
4962
4955
  * @param {string} name Tên voucher / ưu đãi.
4963
- * @param {string} code Nội dung encode vào QR hoặc barcode.
4964
- * @param {"qr_code" | "bar_code"} [display="qr_code"] Loại mã hiển thị.
4965
- * @param {string} merchantName Tên thương hiệu / cửa hàng phát hành voucher.
4956
+ * @param {string} condition Điều kiện áp dụng (chính), hiển thị trên chi tiết vé.
4957
+ * @param {number} expiredAt Hạn sử dụng, epoch milliseconds.
4966
4958
  * @param {string} merchantOaId OA ID của merchant trên Zalo.
4967
- * @param {string} ownerName Tên người nhận voucher.
4968
- * @param {string} condition Điều kiện sử dụng tóm tắt.
4969
- * @param {number} expiredAt Thời điểm hết hạn, epoch milliseconds.
4970
- * @param {number} [remindAt] Thời điểm gửi nhắc hạn, epoch milliseconds.
4971
- * @param {VoucherAction[]} [actions] Danh sách CTA hiển thị trên thẻ.
4959
+ * @param {string} merchantName Tên OA / thương hiệu phát hành voucher.
4960
+ * @param {string} merchantLogoUrl Logo OA, dùng làm logo hiển thị trên voucher.
4961
+ * @param {string} [conditionDetail] Điều kiện áp dụng chi tiết (phụ).
4962
+ * @param {number} [validAt] Thời gian bắt đầu hiệu lực, epoch milliseconds.
4963
+ * @param {string} [code] Mã voucher; không truyền thì tự sinh QR OA của merchant.
4964
+ * @param {"qr_code" | "bar_code"} [display="qr_code"] Loại mã hiển thị.
4965
+ * @param {string} [ownerName] Tên khách hàng sở hữu; không truyền thì không hiển thị trên vé.
4966
+ * @param {string} [interactToken] Token để merchant gửi tin nhắn không tốn phí.
4967
+ * Lấy từ callback `onDataReceived` của {@link showFunctionButtonWidget} khi
4968
+ * người dùng nhấn vào Function Button Widget.
4969
+ * @param {VoucherAction[]} [actions] Danh sách CTA hiển thị trên thẻ (tối đa 2).
4972
4970
  *
4973
- * @returns {Promise<void>} Promise resolve khi tạo thẻ thành công và deeplink đã
4974
- * được mở; reject kèm mã lỗi từ server nếu thất bại.
4971
+ * @returns {Promise<AddVoucherReturns>} Promise resolve khi tạo thẻ thành công và
4972
+ * deeplink đã được mở, trả về `oa_message_token` (chuỗi rỗng nếu server không
4973
+ * trả về); reject kèm mã lỗi từ server nếu thất bại.
4975
4974
  *
4976
4975
  * @example Thêm voucher vào Ví QR:
4977
4976
  * ```ts
4978
4977
  * await addVoucher({
4979
- * name: "Giảm 50k cho đơn từ 150k",
4980
- * code: "SPFOOD50K",
4981
- * merchantName: "Shopee Food",
4982
- * merchantOaId: "2712772826697148176",
4983
- * ownerName: "Nguyễn Văn A",
4984
- * condition: "Áp dụng cho đơn từ 150.000đ.",
4985
- * expiredAt: 1751299200000,
4986
- * remindAt: 1751212800000,
4978
+ * name: "Giảm 50% giá trị đơn hàng",
4979
+ * condition: "Áp dụng cho hóa đơn trên 200.000đ",
4980
+ * expiredAt: 1743440399000,
4981
+ * merchantOaId: "2646373759294038927",
4982
+ * merchantName: "The Face Shop",
4983
+ * merchantLogoUrl: "https://static.example.com/logo.png",
4984
+ * });
4985
+ * ```
4986
+ *
4987
+ * @example Gửi kèm `interactToken` lấy từ Function Button Widget:
4988
+ * ```ts
4989
+ * showFunctionButtonWidget({
4990
+ * id: "orderButton",
4991
+ * type: "ORDER",
4992
+ * text: "Tạo đơn hàng",
4993
+ * onDataReceived: async (interactToken) => {
4994
+ * await addVoucher({
4995
+ * name: "Giảm 50% giá trị đơn hàng",
4996
+ * condition: "Áp dụng cho hóa đơn trên 200.000đ",
4997
+ * expiredAt: 1743440399000,
4998
+ * merchantOaId: "2646373759294038927",
4999
+ * merchantName: "The Face Shop",
5000
+ * merchantLogoUrl: "https://static.example.com/logo.png",
5001
+ * interactToken,
5002
+ * });
5003
+ * },
4987
5004
  * });
4988
5005
  * ```
4989
5006
  */
4990
- declare function addVoucher(args: AsyncCallback<void> & AddVoucherData): Promise<void>;
5007
+ declare function addVoucher(args: AsyncCallback<AddVoucherReturns> & AddVoucherData): Promise<AddVoucherReturns>;
4991
5008
 
4992
5009
  declare const interactOAArgs$1: ZodObject<{
4993
5010
  oaId: ZodString;
@@ -1 +1 @@
1
- var a="2.52.1-beta.1";export{a as version};
1
+ var a="2.52.1-beta.3";export{a as version};