@channel.io/app-sdk-wam 0.18.2 → 0.19.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.
@@ -2,4 +2,5 @@ export * from "./useWamData.js";
2
2
  export * from "./useWamSize.js";
3
3
  export * from "./useCallFunction.js";
4
4
  export * from "./useNativeFunction.js";
5
+ export * from "./useRenderSnapshot.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
@@ -2,4 +2,5 @@ export * from "./useWamData.js";
2
2
  export * from "./useWamSize.js";
3
3
  export * from "./useCallFunction.js";
4
4
  export * from "./useNativeFunction.js";
5
+ export * from "./useRenderSnapshot.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { WamRenderData, WamRenderSnapshot } from "@channel.io/app-sdk-core";
2
+ export interface ResolvedRenderSnapshot<T extends WamRenderData = WamRenderData> {
3
+ wamVersion: number;
4
+ snapshot: WamRenderSnapshot<T> | (Omit<WamRenderSnapshot<T>, "capturedAt"> & {
5
+ capturedAt?: undefined;
6
+ });
7
+ source: "versioned" | "legacy";
8
+ }
9
+ export interface ResolveRenderSnapshotInput {
10
+ wamVersion: unknown;
11
+ renderSnapshot: unknown;
12
+ publicSnapshot?: unknown;
13
+ }
14
+ export declare function resolveRenderSnapshot<T extends WamRenderData = WamRenderData>({ wamVersion, renderSnapshot, publicSnapshot, }: ResolveRenderSnapshotInput): ResolvedRenderSnapshot<T> | undefined;
15
+ /**
16
+ * Reads a persisted WAM render snapshot. Legacy CoS clips that only provide
17
+ * `publicSnapshot` are exposed as renderer/schema version 1.
18
+ */
19
+ export declare function useRenderSnapshot<T extends WamRenderData = WamRenderData>(): ResolvedRenderSnapshot<T> | undefined;
20
+ //# sourceMappingURL=useRenderSnapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderSnapshot.d.ts","sourceRoot":"","sources":["../../src/hooks/useRenderSnapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGjF,MAAM,WAAW,sBAAsB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa;IAC7E,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EACN,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IACjG,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;CAChC;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAcD,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAAE,EAC7E,UAAU,EACV,cAAc,EACd,cAAc,GACf,EAAE,0BAA0B,GAAG,sBAAsB,CAAC,CAAC,CAAC,GAAG,SAAS,CA2BpE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,KACvE,sBAAsB,CAAC,CAAC,CAAC,GAAG,SAAS,CActC"}
@@ -0,0 +1,50 @@
1
+ import { useMemo } from "react";
2
+ import { useWamData } from "./useWamData.js";
3
+ function isRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ function isPositiveInteger(value) {
7
+ return Number.isInteger(value) && Number(value) > 0;
8
+ }
9
+ function isCapturedAt(value) {
10
+ return typeof value === "string" && value.length > 0 && Number.isFinite(Date.parse(value));
11
+ }
12
+ export function resolveRenderSnapshot({ wamVersion, renderSnapshot, publicSnapshot, }) {
13
+ if (isPositiveInteger(wamVersion) &&
14
+ isRecord(renderSnapshot) &&
15
+ isPositiveInteger(renderSnapshot["schemaVersion"]) &&
16
+ isCapturedAt(renderSnapshot["capturedAt"]) &&
17
+ isRecord(renderSnapshot["data"])) {
18
+ return {
19
+ wamVersion,
20
+ snapshot: renderSnapshot,
21
+ source: "versioned",
22
+ };
23
+ }
24
+ if (isRecord(publicSnapshot)) {
25
+ return {
26
+ wamVersion: 1,
27
+ snapshot: {
28
+ schemaVersion: 1,
29
+ data: publicSnapshot,
30
+ },
31
+ source: "legacy",
32
+ };
33
+ }
34
+ return undefined;
35
+ }
36
+ /**
37
+ * Reads a persisted WAM render snapshot. Legacy CoS clips that only provide
38
+ * `publicSnapshot` are exposed as renderer/schema version 1.
39
+ */
40
+ export function useRenderSnapshot() {
41
+ const wamVersion = useWamData("wamVersion");
42
+ const renderSnapshot = useWamData("renderSnapshot");
43
+ const publicSnapshot = useWamData("publicSnapshot");
44
+ return useMemo(() => resolveRenderSnapshot({
45
+ wamVersion,
46
+ renderSnapshot,
47
+ publicSnapshot,
48
+ }), [publicSnapshot, renderSnapshot, wamVersion]);
49
+ }
50
+ //# sourceMappingURL=useRenderSnapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderSnapshot.js","sourceRoot":"","sources":["../../src/hooks/useRenderSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAe7C,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,qBAAqB,CAA0C,EAC7E,UAAU,EACV,cAAc,EACd,cAAc,GACa;IAC3B,IACE,iBAAiB,CAAC,UAAU,CAAC;QAC7B,QAAQ,CAAC,cAAc,CAAC;QACxB,iBAAiB,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QAClD,YAAY,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;QAC1C,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAChC,CAAC;QACD,OAAO;YACL,UAAU;YACV,QAAQ,EAAE,cAAiD;YAC3D,MAAM,EAAE,WAAW;SACpB,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7B,OAAO;YACL,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE;gBACR,aAAa,EAAE,CAAC;gBAChB,IAAI,EAAE,cAAmB;aAC1B;YACD,MAAM,EAAE,QAAQ;SACjB,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAE/B,MAAM,UAAU,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,cAAc,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAEpD,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,qBAAqB,CAAI;QACvB,UAAU;QACV,cAAc;QACd,cAAc;KACf,CAAC,EACJ,CAAC,cAAc,EAAE,cAAc,EAAE,UAAU,CAAC,CAC7C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useRenderSnapshot.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderSnapshot.test.d.ts","sourceRoot":"","sources":["../../src/hooks/useRenderSnapshot.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { resolveRenderSnapshot } from "./useRenderSnapshot.js";
3
+ describe("resolveRenderSnapshot", () => {
4
+ it("resolves a versioned render snapshot", () => {
5
+ expect(resolveRenderSnapshot({
6
+ wamVersion: 2,
7
+ renderSnapshot: {
8
+ schemaVersion: 3,
9
+ capturedAt: "2026-08-03T12:00:00.000Z",
10
+ data: { summary: { title: "Trend" } },
11
+ },
12
+ })).toEqual({
13
+ wamVersion: 2,
14
+ snapshot: {
15
+ schemaVersion: 3,
16
+ capturedAt: "2026-08-03T12:00:00.000Z",
17
+ data: { summary: { title: "Trend" } },
18
+ },
19
+ source: "versioned",
20
+ });
21
+ });
22
+ it("reads a legacy public snapshot as version 1", () => {
23
+ expect(resolveRenderSnapshot({
24
+ wamVersion: undefined,
25
+ renderSnapshot: undefined,
26
+ publicSnapshot: { rows: [{ rank: 1 }] },
27
+ })).toMatchObject({
28
+ wamVersion: 1,
29
+ snapshot: {
30
+ schemaVersion: 1,
31
+ data: { rows: [{ rank: 1 }] },
32
+ },
33
+ source: "legacy",
34
+ });
35
+ });
36
+ it("rejects malformed or unsupported envelope values", () => {
37
+ expect(resolveRenderSnapshot({
38
+ wamVersion: 0,
39
+ renderSnapshot: {
40
+ schemaVersion: 1,
41
+ capturedAt: "not-a-date",
42
+ data: [],
43
+ },
44
+ })).toBeUndefined();
45
+ });
46
+ });
47
+ //# sourceMappingURL=useRenderSnapshot.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderSnapshot.test.js","sourceRoot":"","sources":["../../src/hooks/useRenderSnapshot.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,CACJ,qBAAqB,CAAC;YACpB,UAAU,EAAE,CAAC;YACb,cAAc,EAAE;gBACd,aAAa,EAAE,CAAC;gBAChB,UAAU,EAAE,0BAA0B;gBACtC,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;aACtC;SACF,CAAC,CACH,CAAC,OAAO,CAAC;YACR,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE;gBACR,aAAa,EAAE,CAAC;gBAChB,UAAU,EAAE,0BAA0B;gBACtC,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;aACtC;YACD,MAAM,EAAE,WAAW;SACpB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CACJ,qBAAqB,CAAC;YACpB,UAAU,EAAE,SAAS;YACrB,cAAc,EAAE,SAAS;YACzB,cAAc,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;SACxC,CAAC,CACH,CAAC,aAAa,CAAC;YACd,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE;gBACR,aAAa,EAAE,CAAC;gBAChB,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;aAC9B;YACD,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,CACJ,qBAAqB,CAAC;YACpB,UAAU,EAAE,CAAC;YACb,cAAc,EAAE;gBACd,aAAa,EAAE,CAAC;gBAChB,UAAU,EAAE,YAAY;gBACxB,IAAI,EAAE,EAAE;aACT;SACF,CAAC,CACH,CAAC,aAAa,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@channel.io/app-sdk-wam",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "description": "React SDK for Channel.io WAM (Web App Module)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,9 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
- "dependencies": {},
18
+ "dependencies": {
19
+ "@channel.io/app-sdk-core": "0.19.0"
20
+ },
19
21
  "peerDependencies": {
20
22
  "react": ">=17.0.0"
21
23
  },