@wix/himalaya-cli 0.1309.0 → 0.1311.0
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.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/delivery-contract.d.ts +3 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/delivery.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/host-session.d.ts +31 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/index.d.ts +1 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-contract.d.ts +39 -15
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-wire.d.ts +2 -4
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments.d.ts +11 -12
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/define-app.d.ts +13 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/apple-iap-contract.d.ts +17 -9
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-order-backend.d.ts +6 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +119 -65
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +125 -35
- package/dist/cli.mjs +1286 -677
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/himi-json-output.md +29 -1
- package/guides/iap-products.md +51 -2
- package/guides/qa-builds.md +16 -12
- package/guides/sdk-reference.json +80 -26
- package/package.json +2 -2
|
@@ -156,7 +156,7 @@ function createPurchaseCoordinator(deps) {
|
|
|
156
156
|
if (!isCurrent(session)) return noDelivery();
|
|
157
157
|
const wasAllowed = item.finishAllowed;
|
|
158
158
|
if (delivered.signInLost && !wasAllowed) {
|
|
159
|
-
blockWithoutSession(item
|
|
159
|
+
blockWithoutSession(item);
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
162
|
if (await deliverItem(session, item, context)) delivered.finished = true;
|
|
@@ -165,9 +165,8 @@ function createPurchaseCoordinator(deps) {
|
|
|
165
165
|
}
|
|
166
166
|
return delivered;
|
|
167
167
|
}
|
|
168
|
-
function blockWithoutSession(item
|
|
169
|
-
|
|
170
|
-
block(item.state, foreign ? "ownershipConflict" : "signInRequired", null);
|
|
168
|
+
function blockWithoutSession(item) {
|
|
169
|
+
block(item.state, item.transaction.appAccountToken === null ? "ownershipConflict" : "signInRequired", null);
|
|
171
170
|
}
|
|
172
171
|
async function deliverItem(session, item, context) {
|
|
173
172
|
if (!item.finishAllowed) {
|
|
@@ -176,7 +175,7 @@ function createPurchaseCoordinator(deps) {
|
|
|
176
175
|
return complete(session, item);
|
|
177
176
|
}
|
|
178
177
|
async function confirmAccess(session, item, context) {
|
|
179
|
-
if (
|
|
178
|
+
if (item.transaction.appAccountToken === null) {
|
|
180
179
|
block(item.state, "ownershipConflict", null);
|
|
181
180
|
return false;
|
|
182
181
|
}
|
|
@@ -368,6 +367,7 @@ function createPurchaseCoordinator(deps) {
|
|
|
368
367
|
const known = new Set([...items.keys()].filter((key) => items.get(key).state.productId === context.productId));
|
|
369
368
|
pendingApproval = { productId: context.productId, token: context.appAccountToken, known };
|
|
370
369
|
setOutcome("awaitingApproval");
|
|
370
|
+
deps.onAwaitingApproval?.(context.productId);
|
|
371
371
|
return true;
|
|
372
372
|
}
|
|
373
373
|
function setOutcome(next) {
|
|
@@ -459,10 +459,10 @@ function decodeContext(settled, isContext) {
|
|
|
459
459
|
return { kind: "unavailable", retryAfterMs: retryAfter(raw.retryAfterMs) };
|
|
460
460
|
}
|
|
461
461
|
function isPurchaseContext(value) {
|
|
462
|
-
return isMemberContext(value) && isObject(value) && isNonEmpty(value.productId);
|
|
462
|
+
return isMemberContext(value) && isObject(value) && isNonEmpty(value.productId) && isNonEmpty(value.appAccountToken);
|
|
463
463
|
}
|
|
464
464
|
function isMemberContext(value) {
|
|
465
|
-
return isObject(value) && isNonEmpty(value.
|
|
465
|
+
return isObject(value) && isNonEmpty(value.scopeKey);
|
|
466
466
|
}
|
|
467
467
|
function retryAfter(value) {
|
|
468
468
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
@@ -852,6 +852,98 @@ function onlineProgramItem(program, commerceDisplayPrice) {
|
|
|
852
852
|
return { reference: { kind: ONLINE_PROGRAM, id }, ...commerceDisplayPrice ? { commerceDisplayPrice } : {} };
|
|
853
853
|
}
|
|
854
854
|
|
|
855
|
+
// ../../core/sdk/iap/src/wix-payments-contract.ts
|
|
856
|
+
var HIMALAYA_SERVE_IAP_ROUTE = { prefix: "/himalaya-serve/v1/iap" };
|
|
857
|
+
var APPLE_SALE_RULES = {
|
|
858
|
+
onlineProgram: { appProductId: (id) => id, productType: "NON_CONSUMABLE" }
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
// ../../core/sdk/iap/src/host-session.ts
|
|
862
|
+
var SIGNED_OUT = {
|
|
863
|
+
generation: 0,
|
|
864
|
+
kind: "signedOut",
|
|
865
|
+
memberId: null,
|
|
866
|
+
siteId: null,
|
|
867
|
+
appId: null,
|
|
868
|
+
ready: false,
|
|
869
|
+
epoch: 0
|
|
870
|
+
};
|
|
871
|
+
var KINDS = /* @__PURE__ */ new Set(["member", "visitor", "owner", "signedOut"]);
|
|
872
|
+
function createHostSession(source) {
|
|
873
|
+
let seen = -1;
|
|
874
|
+
let latest = SIGNED_OUT;
|
|
875
|
+
const byGeneration = /* @__PURE__ */ new Map();
|
|
876
|
+
function pull() {
|
|
877
|
+
const snap = parseSession(source.current());
|
|
878
|
+
if (snap.generation < seen) return latest;
|
|
879
|
+
seen = snap.generation;
|
|
880
|
+
latest = snap;
|
|
881
|
+
const expectation = expectationOf(snap);
|
|
882
|
+
if (expectation && !byGeneration.has(snap.generation)) byGeneration.set(snap.generation, expectation);
|
|
883
|
+
return snap;
|
|
884
|
+
}
|
|
885
|
+
return {
|
|
886
|
+
identityBound: source.identityBound,
|
|
887
|
+
current() {
|
|
888
|
+
const snap = pull();
|
|
889
|
+
return { generation: snap.generation, kind: snap.kind };
|
|
890
|
+
},
|
|
891
|
+
identity(session) {
|
|
892
|
+
pull();
|
|
893
|
+
return byGeneration.get(session.generation) ?? null;
|
|
894
|
+
},
|
|
895
|
+
subscribe(listener) {
|
|
896
|
+
return source.subscribe(() => {
|
|
897
|
+
const before = seen;
|
|
898
|
+
pull();
|
|
899
|
+
if (latest.generation >= before) listener();
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
function hostSessionFromGlobal() {
|
|
905
|
+
const api = wixApiGlobal();
|
|
906
|
+
const session = api?.session;
|
|
907
|
+
if (!session || typeof session.current !== "function" || typeof session.subscribe !== "function") {
|
|
908
|
+
return createHostSession({ identityBound: false, current: () => SIGNED_OUT, subscribe: () => () => {
|
|
909
|
+
} });
|
|
910
|
+
}
|
|
911
|
+
return createHostSession({
|
|
912
|
+
identityBound: api?.identityBound === true,
|
|
913
|
+
current: () => session.current(),
|
|
914
|
+
subscribe: (listener) => session.subscribe(listener)
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
function memberIdentityOf(source) {
|
|
918
|
+
return { memberId: (session) => Promise.resolve(source.identity(session)?.memberId ?? null) };
|
|
919
|
+
}
|
|
920
|
+
function readIdentityBound() {
|
|
921
|
+
return wixApiGlobal()?.identityBound === true;
|
|
922
|
+
}
|
|
923
|
+
function expectationOf(snap) {
|
|
924
|
+
if (!snap.ready || snap.kind !== "member" || !snap.memberId || !snap.siteId || !snap.appId) return null;
|
|
925
|
+
return { generation: snap.generation, kind: "member", memberId: snap.memberId, siteId: snap.siteId, appId: snap.appId };
|
|
926
|
+
}
|
|
927
|
+
function parseSession(raw) {
|
|
928
|
+
if (raw === null || typeof raw !== "object") return SIGNED_OUT;
|
|
929
|
+
const value = raw;
|
|
930
|
+
const kind = value.kind;
|
|
931
|
+
if (typeof value.generation !== "number" || !Number.isSafeInteger(value.generation)) return SIGNED_OUT;
|
|
932
|
+
if (typeof kind !== "string" || !KINDS.has(kind)) return SIGNED_OUT;
|
|
933
|
+
return {
|
|
934
|
+
generation: value.generation,
|
|
935
|
+
kind,
|
|
936
|
+
memberId: typeof value.memberId === "string" && value.memberId.length > 0 ? value.memberId : null,
|
|
937
|
+
siteId: typeof value.siteId === "string" && value.siteId.length > 0 ? value.siteId : null,
|
|
938
|
+
appId: typeof value.appId === "string" && value.appId.length > 0 ? value.appId : null,
|
|
939
|
+
ready: value.ready === true,
|
|
940
|
+
epoch: typeof value.epoch === "number" ? value.epoch : 0
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
function wixApiGlobal() {
|
|
944
|
+
return globalThis.himalaya?.wixApi;
|
|
945
|
+
}
|
|
946
|
+
|
|
855
947
|
// ../../core/sdk/iap/src/wix-payments-wire.ts
|
|
856
948
|
function startPaymentCall(scope, wixTransactionId) {
|
|
857
949
|
return post(scope, "/payments/start", { appId: scope.binding.purchasesAppId, wixTransactionId });
|
|
@@ -859,9 +951,6 @@ function startPaymentCall(scope, wixTransactionId) {
|
|
|
859
951
|
function completePaymentCall(scope, signedTransaction) {
|
|
860
952
|
return post(scope, "/payments/complete", { appId: scope.binding.purchasesAppId, apple: { signedTransaction } });
|
|
861
953
|
}
|
|
862
|
-
function customerIdCall(scope) {
|
|
863
|
-
return get(scope, `/customer-id?appId=${encodeURIComponent(scope.binding.purchasesAppId)}`);
|
|
864
|
-
}
|
|
865
954
|
function paymentCall(scope, paymentId) {
|
|
866
955
|
return get(scope, `/payments/${encodeURIComponent(paymentId)}`);
|
|
867
956
|
}
|
|
@@ -869,16 +958,13 @@ function isRoutePrefix(prefix) {
|
|
|
869
958
|
return /^\/[A-Za-z0-9._~\-/]*[A-Za-z0-9._~-]$/.test(prefix);
|
|
870
959
|
}
|
|
871
960
|
function decodeStarted(raw, expected) {
|
|
872
|
-
if (!isObject3(raw) || !isStoreProductId(raw.storeProductId) || !isUUID(raw.
|
|
961
|
+
if (!isObject3(raw) || !isStoreProductId(raw.storeProductId) || !isUUID(raw.appAccountToken)) return null;
|
|
873
962
|
const payment = decodePayment(raw.payment, expected);
|
|
874
|
-
return payment && { payment, storeProductId: raw.storeProductId,
|
|
963
|
+
return payment && { payment, storeProductId: raw.storeProductId, appAccountToken: raw.appAccountToken };
|
|
875
964
|
}
|
|
876
965
|
function decodePaymentAnswer(raw, expected) {
|
|
877
966
|
return isObject3(raw) ? decodePayment(raw.payment, expected) : null;
|
|
878
967
|
}
|
|
879
|
-
function decodeCustomerId(raw) {
|
|
880
|
-
return isObject3(raw) && isUUID(raw.customerId) ? raw.customerId : null;
|
|
881
|
-
}
|
|
882
968
|
function decodePayment(raw, expected) {
|
|
883
969
|
if (!isObject3(raw) || !hasPaymentIds(raw) || !echoes(raw, expected) || !hasValidOptionals(raw)) return null;
|
|
884
970
|
const status = ownValue(STATUSES, raw.status);
|
|
@@ -993,7 +1079,7 @@ function createWixIapClient(deps) {
|
|
|
993
1079
|
codes: START_PAYMENT_CODES,
|
|
994
1080
|
request: (scope) => startPaymentCall(scope, input.wixTransactionId),
|
|
995
1081
|
decode: (raw, scope) => {
|
|
996
|
-
const started = decodeStarted(raw, { ...
|
|
1082
|
+
const started = decodeStarted(raw, { ...expectationOf2(scope), wixTransactionId: input.wixTransactionId });
|
|
997
1083
|
return started && { status: "started", ...started };
|
|
998
1084
|
}
|
|
999
1085
|
});
|
|
@@ -1006,22 +1092,11 @@ function createWixIapClient(deps) {
|
|
|
1006
1092
|
codes: COMPLETE_PAYMENT_CODES,
|
|
1007
1093
|
request: (scope) => completePaymentCall(scope, transaction.signedTransaction),
|
|
1008
1094
|
decode: (raw, scope) => {
|
|
1009
|
-
const payment = decodePaymentAnswer(raw,
|
|
1095
|
+
const payment = decodePaymentAnswer(raw, expectationOf2(scope));
|
|
1010
1096
|
return payment && { status: "matched", payment };
|
|
1011
1097
|
}
|
|
1012
1098
|
});
|
|
1013
1099
|
}
|
|
1014
|
-
function getCustomerId() {
|
|
1015
|
-
return run({
|
|
1016
|
-
operation: "getCustomerId",
|
|
1017
|
-
codes: GET_CUSTOMER_ID_CODES,
|
|
1018
|
-
request: customerIdCall,
|
|
1019
|
-
decode: (raw) => {
|
|
1020
|
-
const customerId = decodeCustomerId(raw);
|
|
1021
|
-
return customerId ? { status: "found", customerId } : null;
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
1100
|
function getPayment(input) {
|
|
1026
1101
|
if (!isUUID(input.paymentId)) return Promise.resolve(failure("getPayment", "invalidArgument"));
|
|
1027
1102
|
return run({
|
|
@@ -1029,7 +1104,7 @@ function createWixIapClient(deps) {
|
|
|
1029
1104
|
codes: GET_PAYMENT_CODES,
|
|
1030
1105
|
request: (scope) => paymentCall(scope, input.paymentId),
|
|
1031
1106
|
decode: (raw, scope) => {
|
|
1032
|
-
const payment = decodePaymentAnswer(raw, { ...
|
|
1107
|
+
const payment = decodePaymentAnswer(raw, { ...expectationOf2(scope), paymentId: input.paymentId });
|
|
1033
1108
|
return payment && { status: "found", payment };
|
|
1034
1109
|
}
|
|
1035
1110
|
});
|
|
@@ -1062,17 +1137,26 @@ function createWixIapClient(deps) {
|
|
|
1062
1137
|
const transport = deps.transport ?? bridgeTransport();
|
|
1063
1138
|
if (!transport) return refused(spec.operation, "notEnabled");
|
|
1064
1139
|
if (!isCurrent(scope.session)) return refused(spec.operation, "sessionChanged");
|
|
1065
|
-
const
|
|
1140
|
+
const expectation = boundExpectation(scope.session, deps.transport == null);
|
|
1141
|
+
if (expectation === "refuse") return refused(spec.operation, "notEnabled");
|
|
1142
|
+
const outcome = await attempt(transport, spec.request(scope), spec, expectation);
|
|
1066
1143
|
return isCurrent(scope.session) ? outcome : refused(spec.operation, "sessionChanged");
|
|
1067
1144
|
}
|
|
1145
|
+
function boundExpectation(session, liveHost) {
|
|
1146
|
+
const source = deps.session;
|
|
1147
|
+
if (liveHost && (source.identityBound !== true || !readIdentityBound())) return "refuse";
|
|
1148
|
+
if (typeof source.identity !== "function") return liveHost ? "refuse" : void 0;
|
|
1149
|
+
return source.identity(session) ?? "refuse";
|
|
1150
|
+
}
|
|
1068
1151
|
function isCurrent(session) {
|
|
1069
1152
|
return deps.session.current().generation === session.generation;
|
|
1070
1153
|
}
|
|
1071
|
-
return { startPayment, completePayment,
|
|
1154
|
+
return { startPayment, completePayment, getPayment };
|
|
1072
1155
|
}
|
|
1073
|
-
async function attempt(transport, call, spec) {
|
|
1156
|
+
async function attempt(transport, call, spec, expectation) {
|
|
1074
1157
|
try {
|
|
1075
|
-
|
|
1158
|
+
const answer = expectation ? await transport.call(call.method, call.path, call.body, call.headers, expectation) : await transport.call(call.method, call.path, call.body, call.headers);
|
|
1159
|
+
return { answer };
|
|
1076
1160
|
} catch (error) {
|
|
1077
1161
|
return { failure: classifyFailure(error, spec.operation, spec.codes) };
|
|
1078
1162
|
}
|
|
@@ -1087,7 +1171,7 @@ async function read(call, operation) {
|
|
|
1087
1171
|
function refused(operation, kind) {
|
|
1088
1172
|
return { failure: failure(operation, kind) };
|
|
1089
1173
|
}
|
|
1090
|
-
function
|
|
1174
|
+
function expectationOf2(scope) {
|
|
1091
1175
|
return { appId: scope.binding.purchasesAppId, memberId: scope.memberId };
|
|
1092
1176
|
}
|
|
1093
1177
|
function refuseProof(transaction) {
|
|
@@ -1119,9 +1203,9 @@ var COMPLETE_PAYMENT_CODES = [
|
|
|
1119
1203
|
"NOT_PURCHASED",
|
|
1120
1204
|
"ZERO_PRICE",
|
|
1121
1205
|
"NO_MATCHING_PAYMENT",
|
|
1206
|
+
"PAYMENT_NOT_PENDING",
|
|
1122
1207
|
"APP_NOT_CONFIGURED"
|
|
1123
1208
|
];
|
|
1124
|
-
var GET_CUSTOMER_ID_CODES = ["APP_NOT_CONFIGURED"];
|
|
1125
1209
|
var GET_PAYMENT_CODES = ["NOT_FOUND"];
|
|
1126
1210
|
|
|
1127
1211
|
// ../../core/sdk/iap/src/index.ts
|
|
@@ -1218,11 +1302,14 @@ function decodeTransaction(value) {
|
|
|
1218
1302
|
return { store, signedTransaction, transactionId, originalTransactionId, productId, appAccountToken, environment };
|
|
1219
1303
|
}
|
|
1220
1304
|
export {
|
|
1305
|
+
APPLE_SALE_RULES,
|
|
1306
|
+
HIMALAYA_SERVE_IAP_ROUTE,
|
|
1221
1307
|
IAP_CATALOG_KINDS,
|
|
1222
1308
|
MAX_AUTOMATIC_ATTEMPTS,
|
|
1223
1309
|
MAX_RETRY_DELAY_MS,
|
|
1224
1310
|
appleManagedStore,
|
|
1225
1311
|
consume,
|
|
1312
|
+
createHostSession,
|
|
1226
1313
|
createIapCatalogPricing,
|
|
1227
1314
|
createPricingController,
|
|
1228
1315
|
createPurchaseCoordinator,
|
|
@@ -1232,10 +1319,13 @@ export {
|
|
|
1232
1319
|
getPaywallConfig,
|
|
1233
1320
|
getProducts,
|
|
1234
1321
|
getUnfinishedTransactions,
|
|
1322
|
+
hostSessionFromGlobal,
|
|
1235
1323
|
iapPriceFields,
|
|
1324
|
+
memberIdentityOf,
|
|
1236
1325
|
onlineProgramItem,
|
|
1237
1326
|
purchase,
|
|
1238
1327
|
purchaseForVerification,
|
|
1328
|
+
readIdentityBound,
|
|
1239
1329
|
restore,
|
|
1240
1330
|
version
|
|
1241
1331
|
};
|