@wix/himalaya-cli 0.1309.0 → 0.1310.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 +19 -14
- 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/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 +117 -35
- package/dist/cli.mjs +22 -21
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/qa-builds.md +16 -12
- package/guides/sdk-reference.json +61 -25
- 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,92 @@ function onlineProgramItem(program, commerceDisplayPrice) {
|
|
|
852
852
|
return { reference: { kind: ONLINE_PROGRAM, id }, ...commerceDisplayPrice ? { commerceDisplayPrice } : {} };
|
|
853
853
|
}
|
|
854
854
|
|
|
855
|
+
// ../../core/sdk/iap/src/host-session.ts
|
|
856
|
+
var SIGNED_OUT = {
|
|
857
|
+
generation: 0,
|
|
858
|
+
kind: "signedOut",
|
|
859
|
+
memberId: null,
|
|
860
|
+
siteId: null,
|
|
861
|
+
appId: null,
|
|
862
|
+
ready: false,
|
|
863
|
+
epoch: 0
|
|
864
|
+
};
|
|
865
|
+
var KINDS = /* @__PURE__ */ new Set(["member", "visitor", "owner", "signedOut"]);
|
|
866
|
+
function createHostSession(source) {
|
|
867
|
+
let seen = -1;
|
|
868
|
+
let latest = SIGNED_OUT;
|
|
869
|
+
const byGeneration = /* @__PURE__ */ new Map();
|
|
870
|
+
function pull() {
|
|
871
|
+
const snap = parseSession(source.current());
|
|
872
|
+
if (snap.generation < seen) return latest;
|
|
873
|
+
seen = snap.generation;
|
|
874
|
+
latest = snap;
|
|
875
|
+
const expectation = expectationOf(snap);
|
|
876
|
+
if (expectation && !byGeneration.has(snap.generation)) byGeneration.set(snap.generation, expectation);
|
|
877
|
+
return snap;
|
|
878
|
+
}
|
|
879
|
+
return {
|
|
880
|
+
identityBound: source.identityBound,
|
|
881
|
+
current() {
|
|
882
|
+
const snap = pull();
|
|
883
|
+
return { generation: snap.generation, kind: snap.kind };
|
|
884
|
+
},
|
|
885
|
+
identity(session) {
|
|
886
|
+
pull();
|
|
887
|
+
return byGeneration.get(session.generation) ?? null;
|
|
888
|
+
},
|
|
889
|
+
subscribe(listener) {
|
|
890
|
+
return source.subscribe(() => {
|
|
891
|
+
const before = seen;
|
|
892
|
+
pull();
|
|
893
|
+
if (latest.generation >= before) listener();
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
function hostSessionFromGlobal() {
|
|
899
|
+
const api = wixApiGlobal();
|
|
900
|
+
const session = api?.session;
|
|
901
|
+
if (!session || typeof session.current !== "function" || typeof session.subscribe !== "function") {
|
|
902
|
+
return createHostSession({ identityBound: false, current: () => SIGNED_OUT, subscribe: () => () => {
|
|
903
|
+
} });
|
|
904
|
+
}
|
|
905
|
+
return createHostSession({
|
|
906
|
+
identityBound: api?.identityBound === true,
|
|
907
|
+
current: () => session.current(),
|
|
908
|
+
subscribe: (listener) => session.subscribe(listener)
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
function memberIdentityOf(source) {
|
|
912
|
+
return { memberId: (session) => Promise.resolve(source.identity(session)?.memberId ?? null) };
|
|
913
|
+
}
|
|
914
|
+
function readIdentityBound() {
|
|
915
|
+
return wixApiGlobal()?.identityBound === true;
|
|
916
|
+
}
|
|
917
|
+
function expectationOf(snap) {
|
|
918
|
+
if (!snap.ready || snap.kind !== "member" || !snap.memberId || !snap.siteId || !snap.appId) return null;
|
|
919
|
+
return { generation: snap.generation, kind: "member", memberId: snap.memberId, siteId: snap.siteId, appId: snap.appId };
|
|
920
|
+
}
|
|
921
|
+
function parseSession(raw) {
|
|
922
|
+
if (raw === null || typeof raw !== "object") return SIGNED_OUT;
|
|
923
|
+
const value = raw;
|
|
924
|
+
const kind = value.kind;
|
|
925
|
+
if (typeof value.generation !== "number" || !Number.isSafeInteger(value.generation)) return SIGNED_OUT;
|
|
926
|
+
if (typeof kind !== "string" || !KINDS.has(kind)) return SIGNED_OUT;
|
|
927
|
+
return {
|
|
928
|
+
generation: value.generation,
|
|
929
|
+
kind,
|
|
930
|
+
memberId: typeof value.memberId === "string" && value.memberId.length > 0 ? value.memberId : null,
|
|
931
|
+
siteId: typeof value.siteId === "string" && value.siteId.length > 0 ? value.siteId : null,
|
|
932
|
+
appId: typeof value.appId === "string" && value.appId.length > 0 ? value.appId : null,
|
|
933
|
+
ready: value.ready === true,
|
|
934
|
+
epoch: typeof value.epoch === "number" ? value.epoch : 0
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
function wixApiGlobal() {
|
|
938
|
+
return globalThis.himalaya?.wixApi;
|
|
939
|
+
}
|
|
940
|
+
|
|
855
941
|
// ../../core/sdk/iap/src/wix-payments-wire.ts
|
|
856
942
|
function startPaymentCall(scope, wixTransactionId) {
|
|
857
943
|
return post(scope, "/payments/start", { appId: scope.binding.purchasesAppId, wixTransactionId });
|
|
@@ -859,9 +945,6 @@ function startPaymentCall(scope, wixTransactionId) {
|
|
|
859
945
|
function completePaymentCall(scope, signedTransaction) {
|
|
860
946
|
return post(scope, "/payments/complete", { appId: scope.binding.purchasesAppId, apple: { signedTransaction } });
|
|
861
947
|
}
|
|
862
|
-
function customerIdCall(scope) {
|
|
863
|
-
return get(scope, `/customer-id?appId=${encodeURIComponent(scope.binding.purchasesAppId)}`);
|
|
864
|
-
}
|
|
865
948
|
function paymentCall(scope, paymentId) {
|
|
866
949
|
return get(scope, `/payments/${encodeURIComponent(paymentId)}`);
|
|
867
950
|
}
|
|
@@ -869,16 +952,13 @@ function isRoutePrefix(prefix) {
|
|
|
869
952
|
return /^\/[A-Za-z0-9._~\-/]*[A-Za-z0-9._~-]$/.test(prefix);
|
|
870
953
|
}
|
|
871
954
|
function decodeStarted(raw, expected) {
|
|
872
|
-
if (!isObject3(raw) || !isStoreProductId(raw.storeProductId) || !isUUID(raw.
|
|
955
|
+
if (!isObject3(raw) || !isStoreProductId(raw.storeProductId) || !isUUID(raw.appAccountToken)) return null;
|
|
873
956
|
const payment = decodePayment(raw.payment, expected);
|
|
874
|
-
return payment && { payment, storeProductId: raw.storeProductId,
|
|
957
|
+
return payment && { payment, storeProductId: raw.storeProductId, appAccountToken: raw.appAccountToken };
|
|
875
958
|
}
|
|
876
959
|
function decodePaymentAnswer(raw, expected) {
|
|
877
960
|
return isObject3(raw) ? decodePayment(raw.payment, expected) : null;
|
|
878
961
|
}
|
|
879
|
-
function decodeCustomerId(raw) {
|
|
880
|
-
return isObject3(raw) && isUUID(raw.customerId) ? raw.customerId : null;
|
|
881
|
-
}
|
|
882
962
|
function decodePayment(raw, expected) {
|
|
883
963
|
if (!isObject3(raw) || !hasPaymentIds(raw) || !echoes(raw, expected) || !hasValidOptionals(raw)) return null;
|
|
884
964
|
const status = ownValue(STATUSES, raw.status);
|
|
@@ -993,7 +1073,7 @@ function createWixIapClient(deps) {
|
|
|
993
1073
|
codes: START_PAYMENT_CODES,
|
|
994
1074
|
request: (scope) => startPaymentCall(scope, input.wixTransactionId),
|
|
995
1075
|
decode: (raw, scope) => {
|
|
996
|
-
const started = decodeStarted(raw, { ...
|
|
1076
|
+
const started = decodeStarted(raw, { ...expectationOf2(scope), wixTransactionId: input.wixTransactionId });
|
|
997
1077
|
return started && { status: "started", ...started };
|
|
998
1078
|
}
|
|
999
1079
|
});
|
|
@@ -1006,22 +1086,11 @@ function createWixIapClient(deps) {
|
|
|
1006
1086
|
codes: COMPLETE_PAYMENT_CODES,
|
|
1007
1087
|
request: (scope) => completePaymentCall(scope, transaction.signedTransaction),
|
|
1008
1088
|
decode: (raw, scope) => {
|
|
1009
|
-
const payment = decodePaymentAnswer(raw,
|
|
1089
|
+
const payment = decodePaymentAnswer(raw, expectationOf2(scope));
|
|
1010
1090
|
return payment && { status: "matched", payment };
|
|
1011
1091
|
}
|
|
1012
1092
|
});
|
|
1013
1093
|
}
|
|
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
1094
|
function getPayment(input) {
|
|
1026
1095
|
if (!isUUID(input.paymentId)) return Promise.resolve(failure("getPayment", "invalidArgument"));
|
|
1027
1096
|
return run({
|
|
@@ -1029,7 +1098,7 @@ function createWixIapClient(deps) {
|
|
|
1029
1098
|
codes: GET_PAYMENT_CODES,
|
|
1030
1099
|
request: (scope) => paymentCall(scope, input.paymentId),
|
|
1031
1100
|
decode: (raw, scope) => {
|
|
1032
|
-
const payment = decodePaymentAnswer(raw, { ...
|
|
1101
|
+
const payment = decodePaymentAnswer(raw, { ...expectationOf2(scope), paymentId: input.paymentId });
|
|
1033
1102
|
return payment && { status: "found", payment };
|
|
1034
1103
|
}
|
|
1035
1104
|
});
|
|
@@ -1062,17 +1131,26 @@ function createWixIapClient(deps) {
|
|
|
1062
1131
|
const transport = deps.transport ?? bridgeTransport();
|
|
1063
1132
|
if (!transport) return refused(spec.operation, "notEnabled");
|
|
1064
1133
|
if (!isCurrent(scope.session)) return refused(spec.operation, "sessionChanged");
|
|
1065
|
-
const
|
|
1134
|
+
const expectation = boundExpectation(scope.session, deps.transport == null);
|
|
1135
|
+
if (expectation === "refuse") return refused(spec.operation, "notEnabled");
|
|
1136
|
+
const outcome = await attempt(transport, spec.request(scope), spec, expectation);
|
|
1066
1137
|
return isCurrent(scope.session) ? outcome : refused(spec.operation, "sessionChanged");
|
|
1067
1138
|
}
|
|
1139
|
+
function boundExpectation(session, liveHost) {
|
|
1140
|
+
const source = deps.session;
|
|
1141
|
+
if (liveHost && (source.identityBound !== true || !readIdentityBound())) return "refuse";
|
|
1142
|
+
if (typeof source.identity !== "function") return liveHost ? "refuse" : void 0;
|
|
1143
|
+
return source.identity(session) ?? "refuse";
|
|
1144
|
+
}
|
|
1068
1145
|
function isCurrent(session) {
|
|
1069
1146
|
return deps.session.current().generation === session.generation;
|
|
1070
1147
|
}
|
|
1071
|
-
return { startPayment, completePayment,
|
|
1148
|
+
return { startPayment, completePayment, getPayment };
|
|
1072
1149
|
}
|
|
1073
|
-
async function attempt(transport, call, spec) {
|
|
1150
|
+
async function attempt(transport, call, spec, expectation) {
|
|
1074
1151
|
try {
|
|
1075
|
-
|
|
1152
|
+
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);
|
|
1153
|
+
return { answer };
|
|
1076
1154
|
} catch (error) {
|
|
1077
1155
|
return { failure: classifyFailure(error, spec.operation, spec.codes) };
|
|
1078
1156
|
}
|
|
@@ -1087,7 +1165,7 @@ async function read(call, operation) {
|
|
|
1087
1165
|
function refused(operation, kind) {
|
|
1088
1166
|
return { failure: failure(operation, kind) };
|
|
1089
1167
|
}
|
|
1090
|
-
function
|
|
1168
|
+
function expectationOf2(scope) {
|
|
1091
1169
|
return { appId: scope.binding.purchasesAppId, memberId: scope.memberId };
|
|
1092
1170
|
}
|
|
1093
1171
|
function refuseProof(transaction) {
|
|
@@ -1119,9 +1197,9 @@ var COMPLETE_PAYMENT_CODES = [
|
|
|
1119
1197
|
"NOT_PURCHASED",
|
|
1120
1198
|
"ZERO_PRICE",
|
|
1121
1199
|
"NO_MATCHING_PAYMENT",
|
|
1200
|
+
"PAYMENT_NOT_PENDING",
|
|
1122
1201
|
"APP_NOT_CONFIGURED"
|
|
1123
1202
|
];
|
|
1124
|
-
var GET_CUSTOMER_ID_CODES = ["APP_NOT_CONFIGURED"];
|
|
1125
1203
|
var GET_PAYMENT_CODES = ["NOT_FOUND"];
|
|
1126
1204
|
|
|
1127
1205
|
// ../../core/sdk/iap/src/index.ts
|
|
@@ -1223,6 +1301,7 @@ export {
|
|
|
1223
1301
|
MAX_RETRY_DELAY_MS,
|
|
1224
1302
|
appleManagedStore,
|
|
1225
1303
|
consume,
|
|
1304
|
+
createHostSession,
|
|
1226
1305
|
createIapCatalogPricing,
|
|
1227
1306
|
createPricingController,
|
|
1228
1307
|
createPurchaseCoordinator,
|
|
@@ -1232,10 +1311,13 @@ export {
|
|
|
1232
1311
|
getPaywallConfig,
|
|
1233
1312
|
getProducts,
|
|
1234
1313
|
getUnfinishedTransactions,
|
|
1314
|
+
hostSessionFromGlobal,
|
|
1235
1315
|
iapPriceFields,
|
|
1316
|
+
memberIdentityOf,
|
|
1236
1317
|
onlineProgramItem,
|
|
1237
1318
|
purchase,
|
|
1238
1319
|
purchaseForVerification,
|
|
1320
|
+
readIdentityBound,
|
|
1239
1321
|
restore,
|
|
1240
1322
|
version
|
|
1241
1323
|
};
|