@receiz/sdk 97.1.0 → 97.2.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/README.md +37 -3
- package/dist/index.d.ts +238 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +345 -1
- package/dist/react.d.ts +80 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +200 -0
- package/docs/app-runtime-commerce-cloud.md +110 -1
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildReceizIdContinueRequest, createReceizIdIdentity, projectReceizIdentityAccount, readReceizIdentityArtifact, signReceizIdentityLoginProof, verifyReceizIdentityLoginProof, } from "./identity.js";
|
|
2
2
|
export * from "./identity.js";
|
|
3
|
-
export const RECEIZ_SDK_VERSION = "97.
|
|
3
|
+
export const RECEIZ_SDK_VERSION = "97.2.0";
|
|
4
4
|
export const RECEIZ_DEFAULT_BASE_URL = "https://receiz.com";
|
|
5
5
|
export const RECEIZ_WEBHOOK_SIGNATURE_HEADER = "x-receiz-signature";
|
|
6
6
|
export const RECEIZ_WEBHOOK_TIMESTAMP_HEADER = "x-receiz-timestamp";
|
|
@@ -268,6 +268,19 @@ function headersWithIdempotency(headers, idempotencyKey) {
|
|
|
268
268
|
next.set("idempotency-key", idempotencyKey);
|
|
269
269
|
return next;
|
|
270
270
|
}
|
|
271
|
+
function queryParams(input) {
|
|
272
|
+
const params = {};
|
|
273
|
+
for (const [key, value] of Object.entries(input)) {
|
|
274
|
+
if (value === null ||
|
|
275
|
+
value === undefined ||
|
|
276
|
+
typeof value === "string" ||
|
|
277
|
+
typeof value === "number" ||
|
|
278
|
+
typeof value === "boolean") {
|
|
279
|
+
params[key] = value;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return params;
|
|
283
|
+
}
|
|
271
284
|
function usdToCents(value) {
|
|
272
285
|
const trimmed = value.trim();
|
|
273
286
|
if (!/^\d+(\.\d{1,2})?$/.test(trimmed))
|
|
@@ -677,8 +690,57 @@ export class ReceizClient {
|
|
|
677
690
|
bootstrap: (username) => this.request(`/api/connect/login/bootstrap/${encodePathSegment(username)}`),
|
|
678
691
|
authorizeUrl: (options) => this.authorizeUrl(options),
|
|
679
692
|
};
|
|
693
|
+
customers = {
|
|
694
|
+
session: (body, options = {}) => this.delegatedWrite("/api/connect/customers/session", body, options),
|
|
695
|
+
portal: (body) => this.delegatedWrite("/api/connect/customers/portal", body),
|
|
696
|
+
orders: (query = {}) => this.delegated(appendQuery("/api/connect/customers/orders", queryParams(query))),
|
|
697
|
+
rewards: (query = {}) => this.delegated(appendQuery("/api/connect/customers/rewards", queryParams(query))),
|
|
698
|
+
assets: (query = {}) => this.delegated(appendQuery("/api/connect/customers/assets", queryParams(query))),
|
|
699
|
+
};
|
|
700
|
+
merchants = {
|
|
701
|
+
onboard: (body, options = {}) => this.delegatedWrite("/api/connect/merchants/onboard", body, options),
|
|
702
|
+
profile: (query = {}) => this.delegated(appendQuery("/api/connect/merchants/profile", query)),
|
|
703
|
+
capabilities: (query = {}) => this.delegated(appendQuery("/api/connect/merchants/capabilities", query)),
|
|
704
|
+
};
|
|
680
705
|
commerce = {
|
|
681
706
|
oneClickCheckout: (body) => this.oneClickCheckout(body),
|
|
707
|
+
refunds: {
|
|
708
|
+
create: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/refunds", body, options),
|
|
709
|
+
},
|
|
710
|
+
subscriptions: {
|
|
711
|
+
create: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/subscriptions", body, options),
|
|
712
|
+
cancel: (subscriptionId, body, options = {}) => this.delegatedWrite(`/api/connect/commerce/subscriptions/${encodePathSegment(subscriptionId)}/cancel`, body, options),
|
|
713
|
+
},
|
|
714
|
+
shipping: {
|
|
715
|
+
quote: (body) => this.delegatedWrite("/api/connect/commerce/shipping/quote", body),
|
|
716
|
+
update: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/shipping/update", body, options),
|
|
717
|
+
},
|
|
718
|
+
tax: {
|
|
719
|
+
quote: (body) => this.delegatedWrite("/api/connect/commerce/tax/quote", body),
|
|
720
|
+
},
|
|
721
|
+
discounts: {
|
|
722
|
+
create: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/discounts", body, options),
|
|
723
|
+
redeem: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/discounts/redeem", body, options),
|
|
724
|
+
},
|
|
725
|
+
giftCards: {
|
|
726
|
+
issue: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/gift-cards", body, options),
|
|
727
|
+
redeem: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/gift-cards/redeem", body, options),
|
|
728
|
+
},
|
|
729
|
+
accessPasses: {
|
|
730
|
+
issue: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/access-passes", body, options),
|
|
731
|
+
verify: (body) => this.delegatedWrite("/api/connect/commerce/access-passes/verify", body),
|
|
732
|
+
},
|
|
733
|
+
inventory: {
|
|
734
|
+
reserve: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/inventory/reserve", body, options),
|
|
735
|
+
adjust: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/inventory/adjust", body, options),
|
|
736
|
+
},
|
|
737
|
+
fulfillment: {
|
|
738
|
+
update: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/fulfillment", body, options),
|
|
739
|
+
},
|
|
740
|
+
payouts: {
|
|
741
|
+
create: (body, options = {}) => this.delegatedWrite("/api/connect/commerce/payouts", body, options),
|
|
742
|
+
status: (query = {}) => this.delegated(appendQuery("/api/connect/commerce/payouts/status", query)),
|
|
743
|
+
},
|
|
682
744
|
};
|
|
683
745
|
payments = {
|
|
684
746
|
embeddedCheckout: (body) => this.request("/api/payments/embed/checkout", { method: "POST", body }),
|
|
@@ -686,6 +748,7 @@ export class ReceizClient {
|
|
|
686
748
|
};
|
|
687
749
|
media = {
|
|
688
750
|
upload: (file, options = {}) => this.uploadMedia(file, options),
|
|
751
|
+
transform: (body, options = {}) => this.delegatedWrite("/api/connect/media/transform", body, options),
|
|
689
752
|
objectUrl: (query) => appendQuery(`${this.baseUrl}/api/storage/object`, query),
|
|
690
753
|
};
|
|
691
754
|
domains = {
|
|
@@ -708,6 +771,9 @@ export class ReceizClient {
|
|
|
708
771
|
};
|
|
709
772
|
events = {
|
|
710
773
|
subscribe: (body) => this.eventSubscribe(body),
|
|
774
|
+
replay: (body) => this.delegatedWrite("/api/connect/events/replay", body),
|
|
775
|
+
list: (query = {}) => this.delegated(appendQuery("/api/connect/events", queryParams(query))),
|
|
776
|
+
ack: (eventId, body = {}) => this.delegatedWrite(`/api/connect/events/${encodePathSegment(eventId)}/ack`, body),
|
|
711
777
|
};
|
|
712
778
|
proof = {
|
|
713
779
|
query: (query) => this.delegated("/api/connect/proof/query", { method: "POST", body: query }),
|
|
@@ -718,6 +784,56 @@ export class ReceizClient {
|
|
|
718
784
|
body: bodyWithIdempotency(body, body.idempotencyKey),
|
|
719
785
|
headers: headersWithIdempotency(undefined, body.idempotencyKey),
|
|
720
786
|
}),
|
|
787
|
+
status: (jobId) => this.delegated(`/api/connect/jobs/${encodePathSegment(jobId)}`),
|
|
788
|
+
cancel: (jobId, body = {}) => this.delegatedWrite(`/api/connect/jobs/${encodePathSegment(jobId)}/cancel`, body),
|
|
789
|
+
list: (query = {}) => this.delegated(appendQuery("/api/connect/jobs", queryParams(query))),
|
|
790
|
+
};
|
|
791
|
+
permissions = {
|
|
792
|
+
grant: (body, options = {}) => this.delegatedWrite("/api/connect/permissions/grants", body, options),
|
|
793
|
+
revoke: (body, options = {}) => this.delegatedWrite("/api/connect/permissions/revoke", body, options),
|
|
794
|
+
check: (body) => this.delegatedWrite("/api/connect/permissions/check", body),
|
|
795
|
+
roles: (query = {}) => this.delegated(appendQuery("/api/connect/permissions/roles", query)),
|
|
796
|
+
};
|
|
797
|
+
audit = {
|
|
798
|
+
append: (body, options = {}) => this.delegatedWrite("/api/connect/audit/events", body, options),
|
|
799
|
+
query: (query = {}) => this.delegated(appendQuery("/api/connect/audit/events", queryParams(query))),
|
|
800
|
+
export: (query = {}) => this.delegated(appendQuery("/api/connect/audit/export", queryParams(query))),
|
|
801
|
+
};
|
|
802
|
+
risk = {
|
|
803
|
+
scorePayment: (body) => this.delegatedWrite("/api/connect/risk/payment", body),
|
|
804
|
+
scoreAccountRecovery: (body) => this.delegatedWrite("/api/connect/risk/account-recovery", body),
|
|
805
|
+
velocity: (body) => this.delegatedWrite("/api/connect/risk/velocity", body),
|
|
806
|
+
proofActivity: (body) => this.delegatedWrite("/api/connect/risk/proof-activity", body),
|
|
807
|
+
};
|
|
808
|
+
compliance = {
|
|
809
|
+
exportOrders: (query) => this.delegated(appendQuery("/api/connect/compliance/orders", queryParams(query))),
|
|
810
|
+
exportTaxes: (query) => this.delegated(appendQuery("/api/connect/compliance/taxes", queryParams(query))),
|
|
811
|
+
exportPayouts: (query) => this.delegated(appendQuery("/api/connect/compliance/payouts", queryParams(query))),
|
|
812
|
+
exportCustomers: (query) => this.delegated(appendQuery("/api/connect/compliance/customers", queryParams(query))),
|
|
813
|
+
exportAudit: (query) => this.delegated(appendQuery("/api/connect/compliance/audit", queryParams(query))),
|
|
814
|
+
};
|
|
815
|
+
portability = {
|
|
816
|
+
exportStore: (query) => this.delegated(appendQuery("/api/connect/portability/store/export", query)),
|
|
817
|
+
importStore: (body, options = {}) => this.delegatedWrite("/api/connect/portability/store/import", body, options),
|
|
818
|
+
};
|
|
819
|
+
search = {
|
|
820
|
+
query: (body) => this.delegatedWrite("/api/connect/search/query", body),
|
|
821
|
+
products: (body) => this.delegatedWrite("/api/connect/search/products", body),
|
|
822
|
+
pages: (body) => this.delegatedWrite("/api/connect/search/pages", body),
|
|
823
|
+
blog: (body) => this.delegatedWrite("/api/connect/search/blog", body),
|
|
824
|
+
orders: (body) => this.delegatedWrite("/api/connect/search/orders", body),
|
|
825
|
+
customers: (body) => this.delegatedWrite("/api/connect/search/customers", body),
|
|
826
|
+
proofObjects: (body) => this.delegatedWrite("/api/connect/search/proof-objects", body),
|
|
827
|
+
};
|
|
828
|
+
notifications = {
|
|
829
|
+
send: (body, options = {}) => this.delegatedWrite("/api/connect/notifications/send", body, options),
|
|
830
|
+
subscribe: (body, options = {}) => this.delegatedWrite("/api/connect/notifications/subscribe", body, options),
|
|
831
|
+
templates: (query = {}) => this.delegated(appendQuery("/api/connect/notifications/templates", query)),
|
|
832
|
+
};
|
|
833
|
+
releases = {
|
|
834
|
+
pin: (body, options = {}) => this.delegatedWrite("/api/connect/releases/pin", body, options),
|
|
835
|
+
check: (query = {}) => this.delegated(appendQuery("/api/connect/releases/check", query)),
|
|
836
|
+
supported: () => this.request("/api/releases/rails/supported"),
|
|
721
837
|
};
|
|
722
838
|
webhooks = {
|
|
723
839
|
sign: createReceizWebhookSignature,
|
|
@@ -776,6 +892,12 @@ export class ReceizClient {
|
|
|
776
892
|
assertSnapshot: assertReceizProofRegisterSnapshot,
|
|
777
893
|
additionsQuery: receizProofMemoryAdditionsQuery,
|
|
778
894
|
};
|
|
895
|
+
offline = {
|
|
896
|
+
createQueue: createReceizOfflineProofQueue,
|
|
897
|
+
createInMemoryStorage: createReceizInMemoryOfflineProofQueueStorage,
|
|
898
|
+
createLocalStorage: createReceizLocalStorageOfflineProofQueueStorage,
|
|
899
|
+
assertSnapshot: assertReceizOfflineProofQueueSnapshot,
|
|
900
|
+
};
|
|
779
901
|
constructor(options = {}) {
|
|
780
902
|
this.baseUrl = trimTrailingSlash(options.baseUrl ?? RECEIZ_DEFAULT_BASE_URL);
|
|
781
903
|
this.accessToken = options.accessToken;
|
|
@@ -857,6 +979,13 @@ export class ReceizClient {
|
|
|
857
979
|
search: configured(delegatedAvailable, "Connect bearer token required for private proof search."),
|
|
858
980
|
permissions: configured(delegatedAvailable && Boolean(tenantHost), "Connect bearer token and tenantHost are required for tenant permissions."),
|
|
859
981
|
jobs: configured(delegatedAvailable, "Connect bearer token required for durable jobs."),
|
|
982
|
+
audit: configured(delegatedAvailable && Boolean(tenantHost), "Connect bearer token and tenantHost are required for sealed tenant audit events."),
|
|
983
|
+
risk: configured(delegatedAvailable && Boolean(tenantHost), "Connect bearer token and tenantHost are required for risk signals."),
|
|
984
|
+
compliance: configured(delegatedAvailable && Boolean(tenantHost), "Connect bearer token and tenantHost are required for compliance exports."),
|
|
985
|
+
portability: configured(delegatedAvailable && Boolean(tenantHost), "Connect bearer token and tenantHost are required for store portability."),
|
|
986
|
+
notifications: configured(delegatedAvailable && Boolean(tenantHost), "Connect bearer token and tenantHost are required for notifications."),
|
|
987
|
+
offline: configured(true),
|
|
988
|
+
releases: configured(delegatedAvailable && Boolean(tenantHost), "Connect bearer token and tenantHost are required for release rail pinning."),
|
|
860
989
|
},
|
|
861
990
|
};
|
|
862
991
|
}
|
|
@@ -1123,6 +1252,14 @@ export class ReceizClient {
|
|
|
1123
1252
|
throw new Error("receiz_access_token_required");
|
|
1124
1253
|
return this.request(path, { ...options, bearerToken: this.accessToken });
|
|
1125
1254
|
}
|
|
1255
|
+
async delegatedWrite(path, body = {}, options = {}) {
|
|
1256
|
+
const idempotencyKey = options.idempotencyKey ?? (typeof body.idempotencyKey === "string" ? body.idempotencyKey : undefined);
|
|
1257
|
+
return this.delegated(path, {
|
|
1258
|
+
method: "POST",
|
|
1259
|
+
body: bodyWithIdempotency(body, idempotencyKey),
|
|
1260
|
+
headers: headersWithIdempotency(undefined, idempotencyKey),
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1126
1263
|
async delegatedBlob(path, options = {}) {
|
|
1127
1264
|
if (!this.accessToken)
|
|
1128
1265
|
throw new Error("receiz_access_token_required");
|
|
@@ -1957,6 +2094,213 @@ export function receizProofMemoryAdditionsQuery(value, limit) {
|
|
|
1957
2094
|
...(limit === undefined ? {} : { limit }),
|
|
1958
2095
|
};
|
|
1959
2096
|
}
|
|
2097
|
+
function normalizeOfflineQueueItem(value) {
|
|
2098
|
+
const record = ensureRecord(value, "ReceizOfflineProofQueueItem");
|
|
2099
|
+
const issues = [];
|
|
2100
|
+
const id = ensureString(record, "id", issues);
|
|
2101
|
+
const kind = ensureString(record, "kind", issues);
|
|
2102
|
+
if (!isRecord(record.payload))
|
|
2103
|
+
issues.push("payload must be an object");
|
|
2104
|
+
const attempts = record.attempts;
|
|
2105
|
+
if (attempts !== undefined && (typeof attempts !== "number" || !Number.isInteger(attempts) || attempts < 0)) {
|
|
2106
|
+
issues.push("attempts must be a non-negative integer when present");
|
|
2107
|
+
}
|
|
2108
|
+
const item = {
|
|
2109
|
+
id: id ?? "",
|
|
2110
|
+
kind: (kind ?? ""),
|
|
2111
|
+
payload: isRecord(record.payload) ? record.payload : {},
|
|
2112
|
+
createdAt: typeof record.createdAt === "string" && record.createdAt.trim() ? record.createdAt : new Date().toISOString(),
|
|
2113
|
+
attempts: typeof attempts === "number" ? attempts : 0,
|
|
2114
|
+
};
|
|
2115
|
+
if (typeof record.idempotencyKey === "string" && record.idempotencyKey.trim())
|
|
2116
|
+
item.idempotencyKey = record.idempotencyKey;
|
|
2117
|
+
if (record.lastError === null || isRecord(record.lastError))
|
|
2118
|
+
item.lastError = record.lastError;
|
|
2119
|
+
failIfIssues("ReceizOfflineProofQueueItem", issues);
|
|
2120
|
+
return item;
|
|
2121
|
+
}
|
|
2122
|
+
export function assertReceizOfflineProofQueueSnapshot(value) {
|
|
2123
|
+
const record = ensureRecord(value, "ReceizOfflineProofQueueSnapshot");
|
|
2124
|
+
const issues = [];
|
|
2125
|
+
if (record.schema !== "receiz.sdk.offline_proof_queue.v1")
|
|
2126
|
+
issues.push("schema must be receiz.sdk.offline_proof_queue.v1");
|
|
2127
|
+
const ownerId = record.ownerId;
|
|
2128
|
+
if (ownerId !== null && ownerId !== undefined && typeof ownerId !== "string") {
|
|
2129
|
+
issues.push("ownerId must be a string or null when present");
|
|
2130
|
+
}
|
|
2131
|
+
const createdAt = ensureString(record, "createdAt", issues);
|
|
2132
|
+
const updatedAt = ensureString(record, "updatedAt", issues);
|
|
2133
|
+
if (!Array.isArray(record.pending))
|
|
2134
|
+
issues.push("pending must be an array");
|
|
2135
|
+
if (!Array.isArray(record.settled))
|
|
2136
|
+
issues.push("settled must be an array");
|
|
2137
|
+
if (!Array.isArray(record.failed))
|
|
2138
|
+
issues.push("failed must be an array");
|
|
2139
|
+
failIfIssues("ReceizOfflineProofQueueSnapshot", issues);
|
|
2140
|
+
return {
|
|
2141
|
+
schema: "receiz.sdk.offline_proof_queue.v1",
|
|
2142
|
+
ownerId: typeof ownerId === "string" || ownerId === null ? ownerId : null,
|
|
2143
|
+
createdAt: createdAt ?? "",
|
|
2144
|
+
updatedAt: updatedAt ?? "",
|
|
2145
|
+
pending: Array.isArray(record.pending) ? record.pending.map(normalizeOfflineQueueItem) : [],
|
|
2146
|
+
settled: Array.isArray(record.settled) ? record.settled.map(normalizeOfflineQueueItem) : [],
|
|
2147
|
+
failed: Array.isArray(record.failed) ? record.failed.map(normalizeOfflineQueueItem) : [],
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
function parseOfflineProofQueueStorageValue(value) {
|
|
2151
|
+
if (value === null || value === undefined)
|
|
2152
|
+
return null;
|
|
2153
|
+
if (typeof value === "string") {
|
|
2154
|
+
const trimmed = value.trim();
|
|
2155
|
+
if (!trimmed)
|
|
2156
|
+
return null;
|
|
2157
|
+
return assertReceizOfflineProofQueueSnapshot(JSON.parse(trimmed));
|
|
2158
|
+
}
|
|
2159
|
+
return assertReceizOfflineProofQueueSnapshot(value);
|
|
2160
|
+
}
|
|
2161
|
+
export class ReceizOfflineProofQueue {
|
|
2162
|
+
ownerId;
|
|
2163
|
+
createdAt;
|
|
2164
|
+
pendingItems;
|
|
2165
|
+
settledItems;
|
|
2166
|
+
failedItems;
|
|
2167
|
+
storage;
|
|
2168
|
+
constructor(options = {}) {
|
|
2169
|
+
const snapshot = options.snapshot ? assertReceizOfflineProofQueueSnapshot(options.snapshot) : null;
|
|
2170
|
+
this.ownerId = options.ownerId ?? snapshot?.ownerId ?? null;
|
|
2171
|
+
this.createdAt = snapshot?.createdAt ?? new Date().toISOString();
|
|
2172
|
+
this.pendingItems = snapshot?.pending ? [...snapshot.pending] : [];
|
|
2173
|
+
this.settledItems = snapshot?.settled ? [...snapshot.settled] : [];
|
|
2174
|
+
this.failedItems = snapshot?.failed ? [...snapshot.failed] : [];
|
|
2175
|
+
this.storage = options.storage ?? null;
|
|
2176
|
+
}
|
|
2177
|
+
enqueue(item) {
|
|
2178
|
+
const normalized = normalizeOfflineQueueItem(item);
|
|
2179
|
+
if (this.pendingItems.some((pending) => pending.id === normalized.id))
|
|
2180
|
+
return this;
|
|
2181
|
+
if (this.settledItems.some((settled) => settled.id === normalized.id))
|
|
2182
|
+
return this;
|
|
2183
|
+
this.pendingItems.push(normalized);
|
|
2184
|
+
return this;
|
|
2185
|
+
}
|
|
2186
|
+
snapshot() {
|
|
2187
|
+
return {
|
|
2188
|
+
schema: "receiz.sdk.offline_proof_queue.v1",
|
|
2189
|
+
ownerId: this.ownerId,
|
|
2190
|
+
createdAt: this.createdAt,
|
|
2191
|
+
updatedAt: new Date().toISOString(),
|
|
2192
|
+
pending: [...this.pendingItems],
|
|
2193
|
+
settled: [...this.settledItems],
|
|
2194
|
+
failed: [...this.failedItems],
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
async flush() {
|
|
2198
|
+
const snapshot = this.snapshot();
|
|
2199
|
+
if (this.storage)
|
|
2200
|
+
await this.storage.write(snapshot);
|
|
2201
|
+
return snapshot;
|
|
2202
|
+
}
|
|
2203
|
+
async clear() {
|
|
2204
|
+
this.pendingItems = [];
|
|
2205
|
+
this.settledItems = [];
|
|
2206
|
+
this.failedItems = [];
|
|
2207
|
+
if (this.storage?.remove)
|
|
2208
|
+
await this.storage.remove();
|
|
2209
|
+
}
|
|
2210
|
+
async replay(client) {
|
|
2211
|
+
const originalPending = [...this.pendingItems];
|
|
2212
|
+
let settled = 0;
|
|
2213
|
+
let failed = 0;
|
|
2214
|
+
this.pendingItems = [];
|
|
2215
|
+
for (const item of originalPending) {
|
|
2216
|
+
try {
|
|
2217
|
+
await replayOfflineProofQueueItem(client, item);
|
|
2218
|
+
this.settledItems.push({ ...item, attempts: (item.attempts ?? 0) + 1, lastError: null });
|
|
2219
|
+
settled += 1;
|
|
2220
|
+
}
|
|
2221
|
+
catch (error) {
|
|
2222
|
+
const failedItem = {
|
|
2223
|
+
...item,
|
|
2224
|
+
attempts: (item.attempts ?? 0) + 1,
|
|
2225
|
+
lastError: errorDetail(error),
|
|
2226
|
+
};
|
|
2227
|
+
this.failedItems.push(failedItem);
|
|
2228
|
+
failed += 1;
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
await this.flush();
|
|
2232
|
+
return { ok: failed === 0, settled, failed };
|
|
2233
|
+
}
|
|
2234
|
+
toJSON() {
|
|
2235
|
+
return this.snapshot();
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
async function replayOfflineProofQueueItem(client, item) {
|
|
2239
|
+
if (item.kind === "app_state.publish") {
|
|
2240
|
+
return client.appState.publish(item.payload, item.idempotencyKey ? { idempotencyKey: item.idempotencyKey } : {});
|
|
2241
|
+
}
|
|
2242
|
+
if (item.kind === "connect.record") {
|
|
2243
|
+
return client.request("/api/connect/record", {
|
|
2244
|
+
method: "POST",
|
|
2245
|
+
body: bodyWithIdempotency(item.payload, item.idempotencyKey),
|
|
2246
|
+
headers: headersWithIdempotency(undefined, item.idempotencyKey),
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
if (item.kind === "webhook.event") {
|
|
2250
|
+
return client.request("/api/connect/webhooks/replay", {
|
|
2251
|
+
method: "POST",
|
|
2252
|
+
body: bodyWithIdempotency(item.payload, item.idempotencyKey),
|
|
2253
|
+
headers: headersWithIdempotency(undefined, item.idempotencyKey),
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
return client.request("/api/connect/offline/replay", {
|
|
2257
|
+
method: "POST",
|
|
2258
|
+
body: bodyWithIdempotency({ kind: item.kind, payload: item.payload }, item.idempotencyKey),
|
|
2259
|
+
headers: headersWithIdempotency(undefined, item.idempotencyKey),
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
export async function createReceizOfflineProofQueue(options = {}) {
|
|
2263
|
+
const storedSnapshot = options.storage ? parseOfflineProofQueueStorageValue(await options.storage.read()) : null;
|
|
2264
|
+
const queueOptions = {
|
|
2265
|
+
ownerId: options.ownerId ?? storedSnapshot?.ownerId ?? null,
|
|
2266
|
+
};
|
|
2267
|
+
if (options.storage)
|
|
2268
|
+
queueOptions.storage = options.storage;
|
|
2269
|
+
const snapshot = options.snapshot ?? storedSnapshot;
|
|
2270
|
+
if (snapshot)
|
|
2271
|
+
queueOptions.snapshot = snapshot;
|
|
2272
|
+
return new ReceizOfflineProofQueue(queueOptions);
|
|
2273
|
+
}
|
|
2274
|
+
export function createReceizInMemoryOfflineProofQueueStorage(initialValue = null) {
|
|
2275
|
+
let storedText = typeof initialValue === "string"
|
|
2276
|
+
? initialValue
|
|
2277
|
+
: initialValue
|
|
2278
|
+
? JSON.stringify(assertReceizOfflineProofQueueSnapshot(initialValue))
|
|
2279
|
+
: null;
|
|
2280
|
+
return {
|
|
2281
|
+
read: () => storedText,
|
|
2282
|
+
write: (snapshot) => {
|
|
2283
|
+
storedText = JSON.stringify(assertReceizOfflineProofQueueSnapshot(snapshot));
|
|
2284
|
+
},
|
|
2285
|
+
remove: () => {
|
|
2286
|
+
storedText = null;
|
|
2287
|
+
},
|
|
2288
|
+
readText: () => storedText,
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
export function createReceizLocalStorageOfflineProofQueueStorage(key = "receiz:offline-proof-queue:v1", storage = globalThis.localStorage) {
|
|
2292
|
+
if (!storage)
|
|
2293
|
+
throw new Error("receiz_local_storage_unavailable");
|
|
2294
|
+
return {
|
|
2295
|
+
read: () => storage.getItem(key),
|
|
2296
|
+
write: (snapshot) => {
|
|
2297
|
+
storage.setItem(key, JSON.stringify(assertReceizOfflineProofQueueSnapshot(snapshot)));
|
|
2298
|
+
},
|
|
2299
|
+
remove: () => {
|
|
2300
|
+
storage.removeItem(key);
|
|
2301
|
+
},
|
|
2302
|
+
};
|
|
2303
|
+
}
|
|
1960
2304
|
function bodyToString(body) {
|
|
1961
2305
|
if (typeof body === "string")
|
|
1962
2306
|
return body;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import { type JsonObject, type ReceizAppStatePublishInput, type ReceizAppStateResolveInput, type ReceizAppStateResolveResult, type ReceizClient, type ReceizClientOptions, type ReceizMediaUploadOptions, type ReceizOneClickCheckoutRequest, type ReceizOneClickCheckoutResponse, type TwinPromotionApprovalInput } from "./index.js";
|
|
3
|
+
export type ReceizReactClientOptions = ReceizClientOptions & {
|
|
4
|
+
client?: ReceizClient;
|
|
5
|
+
};
|
|
6
|
+
export type ReceizAsyncState<T> = {
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
data: T | null;
|
|
10
|
+
};
|
|
11
|
+
export type ReceizIdentityHook = {
|
|
12
|
+
client: ReceizClient;
|
|
13
|
+
login: () => void;
|
|
14
|
+
logout: () => void;
|
|
15
|
+
authorizeUrl: string | null;
|
|
16
|
+
};
|
|
17
|
+
export type ReceizIdentityHookOptions = ReceizReactClientOptions & {
|
|
18
|
+
authorize?: {
|
|
19
|
+
clientId: string;
|
|
20
|
+
redirectUri: string;
|
|
21
|
+
codeChallenge: string;
|
|
22
|
+
codeChallengeMethod?: "S256" | "plain";
|
|
23
|
+
state?: string;
|
|
24
|
+
scope?: string | string[];
|
|
25
|
+
usernameHint?: string;
|
|
26
|
+
};
|
|
27
|
+
logoutUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
export type ReceizCheckoutHook = ReceizAsyncState<ReceizOneClickCheckoutResponse> & {
|
|
30
|
+
checkout: (request: ReceizOneClickCheckoutRequest) => Promise<ReceizOneClickCheckoutResponse>;
|
|
31
|
+
};
|
|
32
|
+
export type ReceizAppStateHook<TData extends JsonObject = JsonObject> = ReceizAsyncState<ReceizAppStateResolveResult<TData>> & {
|
|
33
|
+
resolve: (input?: ReceizAppStateResolveInput) => Promise<ReceizAppStateResolveResult<TData>>;
|
|
34
|
+
publish: (input: ReceizAppStatePublishInput) => Promise<JsonObject>;
|
|
35
|
+
};
|
|
36
|
+
export type ReceizAppStateHookOptions<TData extends JsonObject = JsonObject> = ReceizReactClientOptions & {
|
|
37
|
+
resolve?: ReceizAppStateResolveInput;
|
|
38
|
+
initial?: ReceizAppStateResolveResult<TData> | null;
|
|
39
|
+
autoResolve?: boolean;
|
|
40
|
+
};
|
|
41
|
+
export type ReceizMediaHook = ReceizAsyncState<JsonObject> & {
|
|
42
|
+
upload: (file: Blob, options?: ReceizMediaUploadOptions) => Promise<JsonObject>;
|
|
43
|
+
};
|
|
44
|
+
type ReceizButtonProps = Omit<ComponentPropsWithoutRef<"button">, "onClick"> & {
|
|
45
|
+
children?: ReactNode;
|
|
46
|
+
};
|
|
47
|
+
type ReceizIdentityButtonProps = ReceizButtonProps & ReceizIdentityHookOptions;
|
|
48
|
+
type ReceizCheckoutButtonProps = ReceizButtonProps & ReceizReactClientOptions & {
|
|
49
|
+
request: ReceizOneClickCheckoutRequest;
|
|
50
|
+
onCheckout?: (response: ReceizOneClickCheckoutResponse) => void;
|
|
51
|
+
};
|
|
52
|
+
type ReceizWalletBalanceProps = ReceizReactClientOptions & {
|
|
53
|
+
tenantHost?: string;
|
|
54
|
+
fallback?: ReactNode;
|
|
55
|
+
};
|
|
56
|
+
type ReceizMediaUploaderProps = Omit<ComponentPropsWithoutRef<"input">, "type" | "onChange"> & ReceizReactClientOptions & {
|
|
57
|
+
uploadOptions?: ReceizMediaUploadOptions;
|
|
58
|
+
onUploaded?: (response: JsonObject) => void;
|
|
59
|
+
};
|
|
60
|
+
type ReceizDomainConnectorProps = ReceizButtonProps & ReceizReactClientOptions & {
|
|
61
|
+
host: string;
|
|
62
|
+
onStatus?: (response: JsonObject) => void;
|
|
63
|
+
};
|
|
64
|
+
type ReceizTwinWriterProps = Omit<ComponentPropsWithoutRef<"button">, "onClick"> & ReceizReactClientOptions & {
|
|
65
|
+
body: TwinPromotionApprovalInput;
|
|
66
|
+
onSaved?: (response: JsonObject) => void;
|
|
67
|
+
children?: ReactNode;
|
|
68
|
+
};
|
|
69
|
+
export declare function useReceizIdentity(options?: ReceizIdentityHookOptions): ReceizIdentityHook;
|
|
70
|
+
export declare function useReceizCheckout(options?: ReceizReactClientOptions): ReceizCheckoutHook;
|
|
71
|
+
export declare function useReceizAppState<TData extends JsonObject = JsonObject>(options?: ReceizAppStateHookOptions<TData>): ReceizAppStateHook<TData>;
|
|
72
|
+
export declare function useReceizMedia(options?: ReceizReactClientOptions): ReceizMediaHook;
|
|
73
|
+
export declare function ReceizIdentityButton(props: ReceizIdentityButtonProps): ReactElement;
|
|
74
|
+
export declare function ReceizCheckoutButton(props: ReceizCheckoutButtonProps): ReactElement;
|
|
75
|
+
export declare function ReceizWalletBalance(props: ReceizWalletBalanceProps): ReactElement;
|
|
76
|
+
export declare function ReceizMediaUploader(props: ReceizMediaUploaderProps): ReactElement;
|
|
77
|
+
export declare function ReceizDomainConnector(props: ReceizDomainConnectorProps): ReactElement;
|
|
78
|
+
export declare function ReceizTwinWriter(props: ReceizTwinWriterProps): ReactElement;
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,E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