@cloudcare/cocos-sdk 0.1.0-alpha.1

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.
Files changed (161) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +31 -0
  3. package/THIRD_PARTY_NOTICES +5 -0
  4. package/bin/cli.cjs +127 -0
  5. package/creator2/package.json +4 -0
  6. package/creator3/package.json +5 -0
  7. package/dist/creator2/core/auto-tracking.d.ts +35 -0
  8. package/dist/creator2/core/auto-tracking.d.ts.map +1 -0
  9. package/dist/creator2/core/auto-tracking.js +337 -0
  10. package/dist/creator2/core/auto-tracking.js.map +1 -0
  11. package/dist/creator2/core/client.d.ts +74 -0
  12. package/dist/creator2/core/client.d.ts.map +1 -0
  13. package/dist/creator2/core/client.js +176 -0
  14. package/dist/creator2/core/client.js.map +1 -0
  15. package/dist/creator2/core/index.d.ts +3 -0
  16. package/dist/creator2/core/index.d.ts.map +1 -0
  17. package/dist/creator2/core/index.js +6 -0
  18. package/dist/creator2/core/index.js.map +1 -0
  19. package/dist/creator2/core/modules.d.ts +159 -0
  20. package/dist/creator2/core/modules.d.ts.map +1 -0
  21. package/dist/creator2/core/modules.js +319 -0
  22. package/dist/creator2/core/modules.js.map +1 -0
  23. package/dist/creator2/core/replay-budget.d.ts +28 -0
  24. package/dist/creator2/core/replay-budget.d.ts.map +1 -0
  25. package/dist/creator2/core/replay-budget.js +113 -0
  26. package/dist/creator2/core/replay-budget.js.map +1 -0
  27. package/dist/creator2/core/replay-diagnostics.d.ts +36 -0
  28. package/dist/creator2/core/replay-diagnostics.d.ts.map +1 -0
  29. package/dist/creator2/core/replay-diagnostics.js +40 -0
  30. package/dist/creator2/core/replay-diagnostics.js.map +1 -0
  31. package/dist/creator2/core/replay-encoding.d.ts +31 -0
  32. package/dist/creator2/core/replay-encoding.d.ts.map +1 -0
  33. package/dist/creator2/core/replay-encoding.js +63 -0
  34. package/dist/creator2/core/replay-encoding.js.map +1 -0
  35. package/dist/creator2/core/replay-pixels.d.ts +3 -0
  36. package/dist/creator2/core/replay-pixels.d.ts.map +1 -0
  37. package/dist/creator2/core/replay-pixels.js +16 -0
  38. package/dist/creator2/core/replay-pixels.js.map +1 -0
  39. package/dist/creator2/core/replay.d.ts +97 -0
  40. package/dist/creator2/core/replay.d.ts.map +1 -0
  41. package/dist/creator2/core/replay.js +578 -0
  42. package/dist/creator2/core/replay.js.map +1 -0
  43. package/dist/creator2/core/transport.d.ts +16 -0
  44. package/dist/creator2/core/transport.d.ts.map +1 -0
  45. package/dist/creator2/core/transport.js +33 -0
  46. package/dist/creator2/core/transport.js.map +1 -0
  47. package/dist/creator2/core/types.d.ts +260 -0
  48. package/dist/creator2/core/types.d.ts.map +1 -0
  49. package/dist/creator2/core/types.js +3 -0
  50. package/dist/creator2/core/types.js.map +1 -0
  51. package/dist/creator2/core/validation.d.ts +14 -0
  52. package/dist/creator2/core/validation.d.ts.map +1 -0
  53. package/dist/creator2/core/validation.js +81 -0
  54. package/dist/creator2/core/validation.js.map +1 -0
  55. package/dist/creator2/core/version.d.ts +9 -0
  56. package/dist/creator2/core/version.d.ts.map +1 -0
  57. package/dist/creator2/core/version.js +14 -0
  58. package/dist/creator2/core/version.js.map +1 -0
  59. package/dist/creator2/creator2/auto.d.ts +9 -0
  60. package/dist/creator2/creator2/auto.d.ts.map +1 -0
  61. package/dist/creator2/creator2/auto.js +65 -0
  62. package/dist/creator2/creator2/auto.js.map +1 -0
  63. package/dist/creator2/creator2/capture.d.ts +17 -0
  64. package/dist/creator2/creator2/capture.d.ts.map +1 -0
  65. package/dist/creator2/creator2/capture.js +162 -0
  66. package/dist/creator2/creator2/capture.js.map +1 -0
  67. package/dist/creator2/creator2/index.d.ts +12 -0
  68. package/dist/creator2/creator2/index.d.ts.map +1 -0
  69. package/dist/creator2/creator2/index.js +41 -0
  70. package/dist/creator2/creator2/index.js.map +1 -0
  71. package/dist/creator2/creator2/transport.d.ts +7 -0
  72. package/dist/creator2/creator2/transport.d.ts.map +1 -0
  73. package/dist/creator2/creator2/transport.js +34 -0
  74. package/dist/creator2/creator2/transport.js.map +1 -0
  75. package/dist/creator3/core/auto-tracking.d.ts +35 -0
  76. package/dist/creator3/core/auto-tracking.d.ts.map +1 -0
  77. package/dist/creator3/core/auto-tracking.js +247 -0
  78. package/dist/creator3/core/auto-tracking.js.map +1 -0
  79. package/dist/creator3/core/client.d.ts +74 -0
  80. package/dist/creator3/core/client.d.ts.map +1 -0
  81. package/dist/creator3/core/client.js +158 -0
  82. package/dist/creator3/core/client.js.map +1 -0
  83. package/dist/creator3/core/index.d.ts +3 -0
  84. package/dist/creator3/core/index.d.ts.map +1 -0
  85. package/dist/creator3/core/index.js +2 -0
  86. package/dist/creator3/core/index.js.map +1 -0
  87. package/dist/creator3/core/modules.d.ts +159 -0
  88. package/dist/creator3/core/modules.d.ts.map +1 -0
  89. package/dist/creator3/core/modules.js +293 -0
  90. package/dist/creator3/core/modules.js.map +1 -0
  91. package/dist/creator3/core/replay-budget.d.ts +28 -0
  92. package/dist/creator3/core/replay-budget.d.ts.map +1 -0
  93. package/dist/creator3/core/replay-budget.js +105 -0
  94. package/dist/creator3/core/replay-budget.js.map +1 -0
  95. package/dist/creator3/core/replay-diagnostics.d.ts +36 -0
  96. package/dist/creator3/core/replay-diagnostics.d.ts.map +1 -0
  97. package/dist/creator3/core/replay-diagnostics.js +36 -0
  98. package/dist/creator3/core/replay-diagnostics.js.map +1 -0
  99. package/dist/creator3/core/replay-encoding.d.ts +31 -0
  100. package/dist/creator3/core/replay-encoding.d.ts.map +1 -0
  101. package/dist/creator3/core/replay-encoding.js +62 -0
  102. package/dist/creator3/core/replay-encoding.js.map +1 -0
  103. package/dist/creator3/core/replay-pixels.d.ts +3 -0
  104. package/dist/creator3/core/replay-pixels.d.ts.map +1 -0
  105. package/dist/creator3/core/replay-pixels.js +13 -0
  106. package/dist/creator3/core/replay-pixels.js.map +1 -0
  107. package/dist/creator3/core/replay.d.ts +97 -0
  108. package/dist/creator3/core/replay.d.ts.map +1 -0
  109. package/dist/creator3/core/replay.js +520 -0
  110. package/dist/creator3/core/replay.js.map +1 -0
  111. package/dist/creator3/core/transport.d.ts +16 -0
  112. package/dist/creator3/core/transport.d.ts.map +1 -0
  113. package/dist/creator3/core/transport.js +27 -0
  114. package/dist/creator3/core/transport.js.map +1 -0
  115. package/dist/creator3/core/types.d.ts +260 -0
  116. package/dist/creator3/core/types.d.ts.map +1 -0
  117. package/dist/creator3/core/types.js +2 -0
  118. package/dist/creator3/core/types.js.map +1 -0
  119. package/dist/creator3/core/validation.d.ts +14 -0
  120. package/dist/creator3/core/validation.d.ts.map +1 -0
  121. package/dist/creator3/core/validation.js +75 -0
  122. package/dist/creator3/core/validation.js.map +1 -0
  123. package/dist/creator3/core/version.d.ts +9 -0
  124. package/dist/creator3/core/version.d.ts.map +1 -0
  125. package/dist/creator3/core/version.js +11 -0
  126. package/dist/creator3/core/version.js.map +1 -0
  127. package/dist/creator3/creator3/auto.d.ts +9 -0
  128. package/dist/creator3/creator3/auto.d.ts.map +1 -0
  129. package/dist/creator3/creator3/auto.js +45 -0
  130. package/dist/creator3/creator3/auto.js.map +1 -0
  131. package/dist/creator3/creator3/capture.d.ts +17 -0
  132. package/dist/creator3/creator3/capture.d.ts.map +1 -0
  133. package/dist/creator3/creator3/capture.js +117 -0
  134. package/dist/creator3/creator3/capture.js.map +1 -0
  135. package/dist/creator3/creator3/index.d.ts +12 -0
  136. package/dist/creator3/creator3/index.d.ts.map +1 -0
  137. package/dist/creator3/creator3/index.js +23 -0
  138. package/dist/creator3/creator3/index.js.map +1 -0
  139. package/dist/creator3/creator3/replay-render-cycle.d.ts +9 -0
  140. package/dist/creator3/creator3/replay-render-cycle.d.ts.map +1 -0
  141. package/dist/creator3/creator3/replay-render-cycle.js +12 -0
  142. package/dist/creator3/creator3/replay-render-cycle.js.map +1 -0
  143. package/dist/creator3/creator3/transport.d.ts +8 -0
  144. package/dist/creator3/creator3/transport.d.ts.map +1 -0
  145. package/dist/creator3/creator3/transport.js +24 -0
  146. package/dist/creator3/creator3/transport.js.map +1 -0
  147. package/dist/creator3/package.json +1 -0
  148. package/extensions/creator2/install-native.cjs +333 -0
  149. package/extensions/creator2/main.js +23 -0
  150. package/extensions/creator2/package.json +6 -0
  151. package/extensions/creator3/dist/builder.js +9 -0
  152. package/extensions/creator3/dist/hooks.js +70 -0
  153. package/extensions/creator3/dist/main.js +4 -0
  154. package/extensions/creator3/install-native.cjs +333 -0
  155. package/extensions/creator3/package.json +10 -0
  156. package/native/android/src/main/java/com/ft/sdk/cocos/FTCocosBridge.java +532 -0
  157. package/native/android/src/main/java/com/ft/sdk/cocos/FTCocosBridgeProvider.java +70 -0
  158. package/native/ios/FTCocosBridge.h +10 -0
  159. package/native/ios/FTCocosBridge.m +470 -0
  160. package/native/ios/FTCocosBridge.podspec +18 -0
  161. package/package.json +60 -0
@@ -0,0 +1,159 @@
1
+ import type { FTNativeTransport } from './transport.js';
2
+ import type { FTAttributes, FTLogLevel, FTLoggerConfig, FTResourceContent, FTResourceMetrics, FTRUMConfig, FTSDKConfig, FTTraceConfig, FTUserData } from './types.js';
3
+ export declare class FTSDKOwnership {
4
+ private mode;
5
+ claimStandalone(): void;
6
+ claimNativeHost(): void;
7
+ releaseNativeHost(): void;
8
+ releaseStandalone(): void;
9
+ assertNativeHostDoesNotOwnSDK(): void;
10
+ }
11
+ /** Base SDK lifecycle and user identity operations. */
12
+ export declare class FTMobileAgent {
13
+ private readonly transport;
14
+ private readonly ownership;
15
+ constructor(transport: FTNativeTransport, ownership?: FTSDKOwnership);
16
+ /**
17
+ * Initializes the native SDK connection.
18
+ *
19
+ * Supply either `datakitUrl`, or both `datawayUrl` and `clientToken`.
20
+ *
21
+ * @param config - Base SDK connection and service settings.
22
+ */
23
+ start(config: FTSDKConfig): void;
24
+ /**
25
+ * Binds a user identity to data collected after this call.
26
+ *
27
+ * @param user - A user ID or a structured user record.
28
+ */
29
+ bindUser(user: FTUserData | string): void;
30
+ /** Removes the currently bound user identity. */
31
+ unbindUser(): void;
32
+ /** Shuts down a standalone native SDK instance. */
33
+ shutdown(): void;
34
+ }
35
+ /** Manual Real User Monitoring operations. */
36
+ export declare class FTRUM {
37
+ private readonly transport;
38
+ private readonly ownership;
39
+ constructor(transport: FTNativeTransport, ownership?: FTSDKOwnership);
40
+ /**
41
+ * Enables RUM with the supplied native and Cocos settings.
42
+ *
43
+ * @param config - RUM application IDs, sampling, and native tracking options.
44
+ */
45
+ start(config: FTRUMConfig): void;
46
+ /**
47
+ * Starts a RUM view.
48
+ *
49
+ * @param name - Application-defined view name.
50
+ * @param attributes - Optional attributes attached to the view.
51
+ */
52
+ startView(name: string, attributes?: FTAttributes): void;
53
+ /**
54
+ * Stops the currently active RUM view.
55
+ *
56
+ * @param attributes - Optional attributes attached when the view stops.
57
+ */
58
+ stopView(attributes?: FTAttributes): void;
59
+ /**
60
+ * Records a completed RUM action.
61
+ *
62
+ * @param name - Application-defined action name.
63
+ * @param type - Action category. @defaultValue `'click'`
64
+ * @param attributes - Optional attributes attached to the action.
65
+ */
66
+ addAction(name: string, type?: string, attributes?: FTAttributes): void;
67
+ /**
68
+ * Starts a RUM action whose completion is detected by the native SDK.
69
+ *
70
+ * @param name - Application-defined action name.
71
+ * @param type - Action category. @defaultValue `'click'`
72
+ * @param attributes - Optional attributes attached to the action.
73
+ */
74
+ startAction(name: string, type?: string, attributes?: FTAttributes): void;
75
+ /**
76
+ * Records an application error.
77
+ *
78
+ * @param message - Human-readable error message.
79
+ * @param stack - Error stack or diagnostic details.
80
+ * @param type - Application-defined error category. @defaultValue `'cocos_error'`
81
+ * @param state - Application state when the error occurred. @defaultValue `'run'`
82
+ * @param attributes - Optional attributes attached to the error.
83
+ */
84
+ addError(message: string, stack: string, type?: string, state?: 'run' | 'startup' | 'unknown', attributes?: FTAttributes): void;
85
+ /**
86
+ * Records a long task.
87
+ *
88
+ * @param stack - Stack or diagnostic details for the task.
89
+ * @param durationNs - Task duration in nanoseconds.
90
+ * @param attributes - Optional attributes attached to the task.
91
+ */
92
+ addLongTask(stack: string, durationNs: number, attributes?: FTAttributes): void;
93
+ /**
94
+ * Starts tracking a resource using an application-defined correlation key.
95
+ *
96
+ * @param key - Key reused by subsequent calls for this resource.
97
+ * @param attributes - Optional attributes attached to the resource.
98
+ */
99
+ startResource(key: string, attributes?: FTAttributes): void;
100
+ /**
101
+ * Stops timing a resource previously started with {@link startResource}.
102
+ *
103
+ * @param key - Key passed to {@link startResource}.
104
+ * @param attributes - Optional attributes attached when timing stops.
105
+ */
106
+ stopResource(key: string, attributes?: FTAttributes): void;
107
+ /**
108
+ * Adds request, response, and optional timing details to a tracked resource.
109
+ *
110
+ * @param key - Key passed to {@link startResource} and {@link stopResource}.
111
+ * @param content - Request and response details safe to collect.
112
+ * @param metrics - Optional network timing metrics.
113
+ */
114
+ addResource(key: string, content: FTResourceContent, metrics?: FTResourceMetrics): void;
115
+ }
116
+ /** Manual logging operations. */
117
+ export declare class FTLogger {
118
+ private readonly transport;
119
+ private readonly ownership;
120
+ constructor(transport: FTNativeTransport, ownership?: FTSDKOwnership);
121
+ /**
122
+ * Enables the native logger.
123
+ *
124
+ * @param config - Logger sampling, filtering, and cache settings.
125
+ */
126
+ start(config: FTLoggerConfig): void;
127
+ /**
128
+ * Writes a custom log entry.
129
+ *
130
+ * @param content - Log message.
131
+ * @param level - Log severity. @defaultValue `'info'`
132
+ * @param attributes - Optional attributes attached to the log.
133
+ */
134
+ log(content: string, level?: FTLogLevel, attributes?: FTAttributes): void;
135
+ }
136
+ /** Distributed-tracing operations. */
137
+ export declare class FTTrace {
138
+ private readonly transport;
139
+ private readonly ownership;
140
+ constructor(transport: FTNativeTransport, ownership?: FTSDKOwnership);
141
+ /**
142
+ * Enables distributed tracing.
143
+ *
144
+ * @param config - Trace sampling and propagation settings.
145
+ */
146
+ start(config: FTTraceConfig): void;
147
+ /**
148
+ * Returns propagation headers for an outgoing request.
149
+ *
150
+ * Pass the same `resourceKey` used for manual RUM resource tracking to link
151
+ * the request with its trace.
152
+ *
153
+ * @param url - Absolute outgoing request URL.
154
+ * @param resourceKey - Optional key used for manual RUM resource tracking.
155
+ * @returns Headers to merge into the outgoing request.
156
+ */
157
+ getHeaders(url: string, resourceKey?: string): Record<string, string>;
158
+ }
159
+ //# sourceMappingURL=modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../../../../src/core/modules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,aAAa,EACb,UAAU,EACX,MAAM,YAAY,CAAC;AASpB,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAA2D;IAEvE,eAAe,IAAI,IAAI;IAOvB,eAAe,IAAI,IAAI;IAOvB,iBAAiB,IAAI,IAAI;IAIzB,iBAAiB,IAAI,IAAI;IAIzB,6BAA6B,IAAI,IAAI;CAKtC;AAkBD,uDAAuD;AACvD,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;gBADT,SAAS,EAAE,iBAAiB,EAC5B,SAAS,iBAAuB;IAGnD;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAchC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI;IAOzC,iDAAiD;IACjD,UAAU,IAAI,IAAI;IAIlB,mDAAmD;IACnD,QAAQ,IAAI,IAAI;CAKjB;AAED,8CAA8C;AAC9C,qBAAa,KAAK;IAEd,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;gBADT,SAAS,EAAE,iBAAiB,EAC5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AAE,iBAAiB,EAC5B,SAAS,iBAAuB;IAGnD;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;IAMnC;;;;;;OAMG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,UAAmB,EAAE,UAAU,CAAC,EAAE,YAAY,GAAG,IAAI;CAOlF;AAED,sCAAsC;AACtC,qBAAa,OAAO;IAEhB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;gBADT,SAAS,EAAE,iBAAiB,EAC5B,SAAS,iBAAuB;IAGnD;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAMlC;;;;;;;;;OASG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAQtE"}
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.FTTrace = exports.FTLogger = exports.FTRUM = exports.FTMobileAgent = exports.FTSDKOwnership = void 0;
15
+ var validation_js_1 = require("./validation.js");
16
+ var version_js_1 = require("./version.js");
17
+ var FTSDKOwnership = /** @class */ (function () {
18
+ function FTSDKOwnership() {
19
+ this.mode = 'unclaimed';
20
+ }
21
+ FTSDKOwnership.prototype.claimStandalone = function () {
22
+ if (this.mode === 'native-host') {
23
+ throw new Error('The native host owns SDK initialization in Hybrid mode');
24
+ }
25
+ this.mode = 'standalone';
26
+ };
27
+ FTSDKOwnership.prototype.claimNativeHost = function () {
28
+ if (this.mode === 'standalone') {
29
+ throw new Error('Standalone initialization and native-host attachment are mutually exclusive');
30
+ }
31
+ this.mode = 'native-host';
32
+ };
33
+ FTSDKOwnership.prototype.releaseNativeHost = function () {
34
+ if (this.mode === 'native-host')
35
+ this.mode = 'unclaimed';
36
+ };
37
+ FTSDKOwnership.prototype.releaseStandalone = function () {
38
+ if (this.mode === 'standalone')
39
+ this.mode = 'unclaimed';
40
+ };
41
+ FTSDKOwnership.prototype.assertNativeHostDoesNotOwnSDK = function () {
42
+ if (this.mode === 'native-host') {
43
+ throw new Error('The native host owns the native SDK in Hybrid mode');
44
+ }
45
+ };
46
+ return FTSDKOwnership;
47
+ }());
48
+ exports.FTSDKOwnership = FTSDKOwnership;
49
+ function compact(value) {
50
+ var source = value;
51
+ var result = {};
52
+ Object.keys(value).forEach(function (key) {
53
+ if (source[key] !== undefined)
54
+ result[key] = source[key];
55
+ });
56
+ return result;
57
+ }
58
+ function withBridgeInfo(attributes) {
59
+ var _a;
60
+ return __assign((_a = {}, _a[version_js_1.FT_COCOS_SDK_BRIDGE_INFO_KEY] = version_js_1.FT_COCOS_SDK_BRIDGE_INFO, _a), (attributes || {}));
61
+ }
62
+ /** Base SDK lifecycle and user identity operations. */
63
+ var FTMobileAgent = /** @class */ (function () {
64
+ function FTMobileAgent(transport, ownership) {
65
+ if (ownership === void 0) { ownership = new FTSDKOwnership(); }
66
+ this.transport = transport;
67
+ this.ownership = ownership;
68
+ }
69
+ /**
70
+ * Initializes the native SDK connection.
71
+ *
72
+ * Supply either `datakitUrl`, or both `datawayUrl` and `clientToken`.
73
+ *
74
+ * @param config - Base SDK connection and service settings.
75
+ */
76
+ FTMobileAgent.prototype.start = function (config) {
77
+ var _a;
78
+ if (!config.datakitUrl && !(config.datawayUrl && config.clientToken)) {
79
+ throw new TypeError('Configure datakitUrl or datawayUrl with clientToken');
80
+ }
81
+ this.ownership.claimStandalone();
82
+ this.transport.invoke('sdk.configure', compact(__assign(__assign({}, config), { globalContext: __assign(__assign({}, (config.globalContext || {})), (_a = {}, _a[version_js_1.FT_COCOS_SDK_VERSION_KEY] = version_js_1.FT_COCOS_SDK_VERSION, _a)) })));
83
+ };
84
+ /**
85
+ * Binds a user identity to data collected after this call.
86
+ *
87
+ * @param user - A user ID or a structured user record.
88
+ */
89
+ FTMobileAgent.prototype.bindUser = function (user) {
90
+ this.transport.invoke('sdk.bindUser', typeof user === 'string' ? { userId: (0, validation_js_1.requireText)(user, 'userId') } : user);
91
+ };
92
+ /** Removes the currently bound user identity. */
93
+ FTMobileAgent.prototype.unbindUser = function () {
94
+ this.transport.invoke('sdk.unbindUser');
95
+ };
96
+ /** Shuts down a standalone native SDK instance. */
97
+ FTMobileAgent.prototype.shutdown = function () {
98
+ this.ownership.assertNativeHostDoesNotOwnSDK();
99
+ this.transport.invoke('sdk.shutdown');
100
+ this.ownership.releaseStandalone();
101
+ };
102
+ return FTMobileAgent;
103
+ }());
104
+ exports.FTMobileAgent = FTMobileAgent;
105
+ /** Manual Real User Monitoring operations. */
106
+ var FTRUM = /** @class */ (function () {
107
+ function FTRUM(transport, ownership) {
108
+ if (ownership === void 0) { ownership = new FTSDKOwnership(); }
109
+ this.transport = transport;
110
+ this.ownership = ownership;
111
+ }
112
+ /**
113
+ * Enables RUM with the supplied native and Cocos settings.
114
+ *
115
+ * @param config - RUM application IDs, sampling, and native tracking options.
116
+ */
117
+ FTRUM.prototype.start = function (config) {
118
+ (0, validation_js_1.samplingRate)(config.sampleRate, 'rum.sampleRate');
119
+ (0, validation_js_1.samplingRate)(config.sessionOnErrorSampleRate, 'rum.sessionOnErrorSampleRate');
120
+ this.ownership.claimStandalone();
121
+ this.transport.invoke('rum.configure', compact(config));
122
+ };
123
+ /**
124
+ * Starts a RUM view.
125
+ *
126
+ * @param name - Application-defined view name.
127
+ * @param attributes - Optional attributes attached to the view.
128
+ */
129
+ FTRUM.prototype.startView = function (name, attributes) {
130
+ this.transport.invoke('rum.startView', {
131
+ name: (0, validation_js_1.requireText)(name, 'view name'),
132
+ attributes: withBridgeInfo(attributes),
133
+ });
134
+ };
135
+ /**
136
+ * Stops the currently active RUM view.
137
+ *
138
+ * @param attributes - Optional attributes attached when the view stops.
139
+ */
140
+ FTRUM.prototype.stopView = function (attributes) {
141
+ this.transport.invoke('rum.stopView', { attributes: withBridgeInfo(attributes) });
142
+ };
143
+ /**
144
+ * Records a completed RUM action.
145
+ *
146
+ * @param name - Application-defined action name.
147
+ * @param type - Action category. @defaultValue `'click'`
148
+ * @param attributes - Optional attributes attached to the action.
149
+ */
150
+ FTRUM.prototype.addAction = function (name, type, attributes) {
151
+ if (type === void 0) { type = 'click'; }
152
+ this.transport.invoke('rum.addAction', {
153
+ name: (0, validation_js_1.requireText)(name, 'action name'),
154
+ type: (0, validation_js_1.requireText)(type, 'action type'),
155
+ attributes: withBridgeInfo(attributes),
156
+ });
157
+ };
158
+ /**
159
+ * Starts a RUM action whose completion is detected by the native SDK.
160
+ *
161
+ * @param name - Application-defined action name.
162
+ * @param type - Action category. @defaultValue `'click'`
163
+ * @param attributes - Optional attributes attached to the action.
164
+ */
165
+ FTRUM.prototype.startAction = function (name, type, attributes) {
166
+ if (type === void 0) { type = 'click'; }
167
+ this.transport.invoke('rum.startAction', {
168
+ name: (0, validation_js_1.requireText)(name, 'action name'),
169
+ type: (0, validation_js_1.requireText)(type, 'action type'),
170
+ attributes: withBridgeInfo(attributes),
171
+ });
172
+ };
173
+ /**
174
+ * Records an application error.
175
+ *
176
+ * @param message - Human-readable error message.
177
+ * @param stack - Error stack or diagnostic details.
178
+ * @param type - Application-defined error category. @defaultValue `'cocos_error'`
179
+ * @param state - Application state when the error occurred. @defaultValue `'run'`
180
+ * @param attributes - Optional attributes attached to the error.
181
+ */
182
+ FTRUM.prototype.addError = function (message, stack, type, state, attributes) {
183
+ if (type === void 0) { type = 'cocos_error'; }
184
+ if (state === void 0) { state = 'run'; }
185
+ this.transport.invoke('rum.addError', {
186
+ message: message,
187
+ stack: stack,
188
+ type: type,
189
+ state: state,
190
+ attributes: withBridgeInfo(attributes),
191
+ });
192
+ };
193
+ /**
194
+ * Records a long task.
195
+ *
196
+ * @param stack - Stack or diagnostic details for the task.
197
+ * @param durationNs - Task duration in nanoseconds.
198
+ * @param attributes - Optional attributes attached to the task.
199
+ */
200
+ FTRUM.prototype.addLongTask = function (stack, durationNs, attributes) {
201
+ this.transport.invoke('rum.addLongTask', {
202
+ stack: stack,
203
+ durationNs: durationNs,
204
+ attributes: withBridgeInfo(attributes),
205
+ });
206
+ };
207
+ /**
208
+ * Starts tracking a resource using an application-defined correlation key.
209
+ *
210
+ * @param key - Key reused by subsequent calls for this resource.
211
+ * @param attributes - Optional attributes attached to the resource.
212
+ */
213
+ FTRUM.prototype.startResource = function (key, attributes) {
214
+ this.transport.invoke('rum.startResource', {
215
+ key: (0, validation_js_1.requireText)(key, 'resource key'),
216
+ attributes: withBridgeInfo(attributes),
217
+ });
218
+ };
219
+ /**
220
+ * Stops timing a resource previously started with {@link startResource}.
221
+ *
222
+ * @param key - Key passed to {@link startResource}.
223
+ * @param attributes - Optional attributes attached when timing stops.
224
+ */
225
+ FTRUM.prototype.stopResource = function (key, attributes) {
226
+ this.transport.invoke('rum.stopResource', {
227
+ key: (0, validation_js_1.requireText)(key, 'resource key'),
228
+ attributes: withBridgeInfo(attributes),
229
+ });
230
+ };
231
+ /**
232
+ * Adds request, response, and optional timing details to a tracked resource.
233
+ *
234
+ * @param key - Key passed to {@link startResource} and {@link stopResource}.
235
+ * @param content - Request and response details safe to collect.
236
+ * @param metrics - Optional network timing metrics.
237
+ */
238
+ FTRUM.prototype.addResource = function (key, content, metrics) {
239
+ this.transport.invoke('rum.addResource', {
240
+ key: (0, validation_js_1.requireText)(key, 'resource key'),
241
+ content: content,
242
+ metrics: metrics,
243
+ });
244
+ };
245
+ return FTRUM;
246
+ }());
247
+ exports.FTRUM = FTRUM;
248
+ /** Manual logging operations. */
249
+ var FTLogger = /** @class */ (function () {
250
+ function FTLogger(transport, ownership) {
251
+ if (ownership === void 0) { ownership = new FTSDKOwnership(); }
252
+ this.transport = transport;
253
+ this.ownership = ownership;
254
+ }
255
+ /**
256
+ * Enables the native logger.
257
+ *
258
+ * @param config - Logger sampling, filtering, and cache settings.
259
+ */
260
+ FTLogger.prototype.start = function (config) {
261
+ (0, validation_js_1.samplingRate)(config.sampleRate, 'logger.sampleRate');
262
+ this.ownership.claimStandalone();
263
+ this.transport.invoke('logger.configure', compact(config));
264
+ };
265
+ /**
266
+ * Writes a custom log entry.
267
+ *
268
+ * @param content - Log message.
269
+ * @param level - Log severity. @defaultValue `'info'`
270
+ * @param attributes - Optional attributes attached to the log.
271
+ */
272
+ FTLogger.prototype.log = function (content, level, attributes) {
273
+ if (level === void 0) { level = 'info'; }
274
+ this.transport.invoke('logger.log', {
275
+ content: content,
276
+ level: level,
277
+ attributes: withBridgeInfo(attributes),
278
+ });
279
+ };
280
+ return FTLogger;
281
+ }());
282
+ exports.FTLogger = FTLogger;
283
+ /** Distributed-tracing operations. */
284
+ var FTTrace = /** @class */ (function () {
285
+ function FTTrace(transport, ownership) {
286
+ if (ownership === void 0) { ownership = new FTSDKOwnership(); }
287
+ this.transport = transport;
288
+ this.ownership = ownership;
289
+ }
290
+ /**
291
+ * Enables distributed tracing.
292
+ *
293
+ * @param config - Trace sampling and propagation settings.
294
+ */
295
+ FTTrace.prototype.start = function (config) {
296
+ (0, validation_js_1.samplingRate)(config.sampleRate, 'trace.sampleRate');
297
+ this.ownership.claimStandalone();
298
+ this.transport.invoke('trace.configure', compact(config));
299
+ };
300
+ /**
301
+ * Returns propagation headers for an outgoing request.
302
+ *
303
+ * Pass the same `resourceKey` used for manual RUM resource tracking to link
304
+ * the request with its trace.
305
+ *
306
+ * @param url - Absolute outgoing request URL.
307
+ * @param resourceKey - Optional key used for manual RUM resource tracking.
308
+ * @returns Headers to merge into the outgoing request.
309
+ */
310
+ FTTrace.prototype.getHeaders = function (url, resourceKey) {
311
+ return this.transport.invoke('trace.getHeaders', {
312
+ url: (0, validation_js_1.requireText)(url, 'url'),
313
+ resourceKey: resourceKey,
314
+ }) || {};
315
+ };
316
+ return FTTrace;
317
+ }());
318
+ exports.FTTrace = FTTrace;
319
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","sourceRoot":"","sources":["../../../../../src/core/modules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAYA,iDAA4D;AAC5D,2CAKsB;AAEtB;IAAA;QACU,SAAI,GAA+C,WAAW,CAAC;IA6BzE,CAAC;IA3BC,wCAAe,GAAf;QACE,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;IAED,wCAAe,GAAf;QACE,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;QACjG,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;IAED,0CAAiB,GAAjB;QACE,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa;YAAE,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC3D,CAAC;IAED,0CAAiB,GAAjB;QACE,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;YAAE,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1D,CAAC;IAED,sDAA6B,GAA7B;QACE,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IACH,qBAAC;AAAD,CAAC,AA9BD,IA8BC;AA9BY,wCAAc;AAgC3B,SAAS,OAAO,CAAmB,KAAQ;IACzC,IAAM,MAAM,GAAG,KAAgC,CAAC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,CAAC,AAnCD,IAmCC;AAnCY,0BAAO"}
@@ -0,0 +1,28 @@
1
+ import type { FTResolvedReplayImagePolicy } from './validation.js';
2
+ export declare const REPLAY_KEY_FRAME_BURST_BYTES: number;
3
+ export interface FTReplayCaptureDecision {
4
+ allowed: boolean;
5
+ compressionQuality: number;
6
+ maxImageDimension: number;
7
+ maxFrameBytes: number;
8
+ usedBytes: number;
9
+ priority: boolean;
10
+ reason?: 'budget' | 'throttle';
11
+ }
12
+ /** Rolling image budget. Segment and pointer bytes intentionally remain outside this controller. */
13
+ export declare class FTReplayBudget {
14
+ private readonly policy;
15
+ private entries;
16
+ private lastCaptureAttempt;
17
+ private burstKeys;
18
+ private pressure;
19
+ constructor(policy: FTResolvedReplayImagePolicy);
20
+ reset(): void;
21
+ decide(timestamp: number, priorityKey?: string): FTReplayCaptureDecision;
22
+ record(timestamp: number, byteSize: number, priorityKey?: string): void;
23
+ usedBytes(timestamp: number): number;
24
+ private prune;
25
+ private decision;
26
+ private updatePressure;
27
+ }
28
+ //# sourceMappingURL=replay-budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-budget.d.ts","sourceRoot":"","sources":["../../../../../src/core/replay-budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAInE,eAAO,MAAM,4BAA4B,QAAa,CAAC;AAOvD,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;CAChC;AAED,oGAAoG;AACpG,qBAAa,cAAc;IAMb,OAAO,CAAC,QAAQ,CAAC,MAAM;IALnC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,QAAQ,CAA4D;gBAE/C,MAAM,EAAE,2BAA2B;IAEhE,KAAK,IAAI,IAAI;IAOb,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,uBAAuB;IA+BxE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAUvE,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAKpC,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,QAAQ;IA2BhB,OAAO,CAAC,cAAc;CA0BvB"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.FTReplayBudget = exports.REPLAY_KEY_FRAME_BURST_BYTES = void 0;
15
+ var WINDOW_MS = 60000;
16
+ var THROTTLED_CAPTURE_INTERVAL_MS = 2000;
17
+ exports.REPLAY_KEY_FRAME_BURST_BYTES = 100 * 1024;
18
+ /** Rolling image budget. Segment and pointer bytes intentionally remain outside this controller. */
19
+ var FTReplayBudget = /** @class */ (function () {
20
+ function FTReplayBudget(policy) {
21
+ this.policy = policy;
22
+ this.entries = [];
23
+ this.burstKeys = [];
24
+ this.pressure = 'normal';
25
+ }
26
+ FTReplayBudget.prototype.reset = function () {
27
+ this.entries = [];
28
+ this.lastCaptureAttempt = undefined;
29
+ this.burstKeys = [];
30
+ this.pressure = 'normal';
31
+ };
32
+ FTReplayBudget.prototype.decide = function (timestamp, priorityKey) {
33
+ var used = this.usedBytes(timestamp);
34
+ var ratio = used / this.policy.maxBytesPerMinute;
35
+ this.updatePressure(ratio);
36
+ var hasBurst = priorityKey !== undefined && !this.burstKeys.includes(priorityKey);
37
+ if (ratio >= 1 && !hasBurst)
38
+ return this.decision(false, 0, used, hasBurst, 'budget');
39
+ if (this.policy.adaptiveCapture
40
+ && this.pressure !== 'normal'
41
+ && this.lastCaptureAttempt !== undefined
42
+ && timestamp - this.lastCaptureAttempt < THROTTLED_CAPTURE_INTERVAL_MS
43
+ && !hasBurst) {
44
+ return this.decision(false, 0, used, hasBurst, 'throttle');
45
+ }
46
+ this.lastCaptureAttempt = timestamp;
47
+ var normalRemaining = Math.max(0, this.policy.maxBytesPerMinute - used);
48
+ var available = normalRemaining + (hasBurst ? exports.REPLAY_KEY_FRAME_BURST_BYTES : 0);
49
+ var frameLimit = hasBurst
50
+ ? Math.min(Math.max(this.policy.maxFrameBytes, exports.REPLAY_KEY_FRAME_BURST_BYTES), available)
51
+ : Math.min(this.policy.maxFrameBytes, available);
52
+ return this.decision(frameLimit >= 1024, frameLimit, used, hasBurst, frameLimit >= 1024 ? undefined : 'budget');
53
+ };
54
+ FTReplayBudget.prototype.record = function (timestamp, byteSize, priorityKey) {
55
+ if (!Number.isFinite(byteSize) || byteSize <= 0)
56
+ return;
57
+ this.prune(timestamp);
58
+ this.entries.push({ timestamp: timestamp, byteSize: Math.round(byteSize) });
59
+ if (priorityKey && !this.burstKeys.includes(priorityKey)) {
60
+ this.burstKeys.push(priorityKey);
61
+ if (this.burstKeys.length > 64)
62
+ this.burstKeys.shift();
63
+ }
64
+ };
65
+ FTReplayBudget.prototype.usedBytes = function (timestamp) {
66
+ this.prune(timestamp);
67
+ return this.entries.reduce(function (total, entry) { return total + entry.byteSize; }, 0);
68
+ };
69
+ FTReplayBudget.prototype.prune = function (timestamp) {
70
+ var cutoff = timestamp - WINDOW_MS;
71
+ while (this.entries.length > 0 && this.entries[0].timestamp <= cutoff)
72
+ this.entries.shift();
73
+ };
74
+ FTReplayBudget.prototype.decision = function (allowed, maxFrameBytes, usedBytes, priority, reason) {
75
+ var degraded = this.policy.adaptiveCapture
76
+ && (this.pressure === 'degraded' || this.pressure === 'paused');
77
+ return __assign({ allowed: allowed, compressionQuality: degraded
78
+ ? Math.max(0.25, Math.round(this.policy.compressionQuality * 0.75 * 100) / 100)
79
+ : this.policy.compressionQuality, maxImageDimension: degraded
80
+ ? Math.min(this.policy.maxImageDimension, Math.max(240, Math.floor(this.policy.maxImageDimension * 0.75)))
81
+ : this.policy.maxImageDimension, maxFrameBytes: Math.max(0, Math.floor(maxFrameBytes)), usedBytes: usedBytes, priority: priority }, (reason ? { reason: reason } : {}));
82
+ };
83
+ FTReplayBudget.prototype.updatePressure = function (ratio) {
84
+ if (!this.policy.adaptiveCapture) {
85
+ this.pressure = 'normal';
86
+ return;
87
+ }
88
+ if (ratio >= 1) {
89
+ this.pressure = 'paused';
90
+ return;
91
+ }
92
+ if (ratio >= 0.9) {
93
+ this.pressure = 'degraded';
94
+ return;
95
+ }
96
+ if (this.pressure === 'paused' || this.pressure === 'degraded') {
97
+ if (ratio >= 0.8) {
98
+ this.pressure = 'degraded';
99
+ return;
100
+ }
101
+ }
102
+ if (ratio >= 0.75) {
103
+ this.pressure = 'throttled';
104
+ return;
105
+ }
106
+ if (this.pressure === 'throttled' && ratio >= 0.65)
107
+ return;
108
+ this.pressure = 'normal';
109
+ };
110
+ return FTReplayBudget;
111
+ }());
112
+ exports.FTReplayBudget = FTReplayBudget;
113
+ //# sourceMappingURL=replay-budget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-budget.js","sourceRoot":"","sources":["../../../../../src/core/replay-budget.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,IAAM,SAAS,GAAG,KAAM,CAAC;AACzB,IAAM,6BAA6B,GAAG,IAAK,CAAC;AAC/B,QAAA,4BAA4B,GAAG,GAAG,GAAG,IAAI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