@beinfi/pulse-sdk 0.1.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 +103 -0
- package/dist/ai.d.mts +934 -0
- package/dist/ai.d.ts +934 -0
- package/dist/ai.js +73 -0
- package/dist/ai.mjs +48 -0
- package/dist/checkout.js +1 -0
- package/dist/index.d.mts +1094 -0
- package/dist/index.d.ts +1094 -0
- package/dist/index.js +712 -0
- package/dist/index.mjs +679 -0
- package/package.json +83 -0
package/dist/ai.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/ai.ts
|
|
21
|
+
var ai_exports = {};
|
|
22
|
+
__export(ai_exports, {
|
|
23
|
+
pulseMiddleware: () => pulseMiddleware
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(ai_exports);
|
|
26
|
+
function pulseMiddleware(config) {
|
|
27
|
+
const resolveCustomerId = async () => typeof config.customerId === "function" ? await config.customerId() : config.customerId;
|
|
28
|
+
const trackUsage = async (inputTokens, outputTokens) => {
|
|
29
|
+
const customerId = await resolveCustomerId();
|
|
30
|
+
const session = config.pulse.metering.session(customerId);
|
|
31
|
+
if (inputTokens != null && inputTokens > 0) {
|
|
32
|
+
session.track(config.meters.input, inputTokens, config.metadata);
|
|
33
|
+
}
|
|
34
|
+
if (outputTokens != null && outputTokens > 0) {
|
|
35
|
+
session.track(config.meters.output, outputTokens, config.metadata);
|
|
36
|
+
}
|
|
37
|
+
await session.end();
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
specificationVersion: "v3",
|
|
41
|
+
// Non-streaming (generateText, generateObject)
|
|
42
|
+
wrapGenerate: async ({ doGenerate }) => {
|
|
43
|
+
const result = await doGenerate();
|
|
44
|
+
trackUsage(
|
|
45
|
+
result.usage.inputTokens.total,
|
|
46
|
+
result.usage.outputTokens.total
|
|
47
|
+
).catch(() => {
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
50
|
+
},
|
|
51
|
+
// Streaming (streamText, streamObject)
|
|
52
|
+
wrapStream: async ({ doStream }) => {
|
|
53
|
+
const { stream, ...rest } = await doStream();
|
|
54
|
+
const transformStream = new TransformStream({
|
|
55
|
+
transform(chunk, controller) {
|
|
56
|
+
if (chunk.type === "finish") {
|
|
57
|
+
trackUsage(
|
|
58
|
+
chunk.usage.inputTokens.total,
|
|
59
|
+
chunk.usage.outputTokens.total
|
|
60
|
+
).catch(() => {
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
controller.enqueue(chunk);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return { stream: stream.pipeThrough(transformStream), ...rest };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
pulseMiddleware
|
|
73
|
+
});
|
package/dist/ai.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/ai.ts
|
|
2
|
+
function pulseMiddleware(config) {
|
|
3
|
+
const resolveCustomerId = async () => typeof config.customerId === "function" ? await config.customerId() : config.customerId;
|
|
4
|
+
const trackUsage = async (inputTokens, outputTokens) => {
|
|
5
|
+
const customerId = await resolveCustomerId();
|
|
6
|
+
const session = config.pulse.metering.session(customerId);
|
|
7
|
+
if (inputTokens != null && inputTokens > 0) {
|
|
8
|
+
session.track(config.meters.input, inputTokens, config.metadata);
|
|
9
|
+
}
|
|
10
|
+
if (outputTokens != null && outputTokens > 0) {
|
|
11
|
+
session.track(config.meters.output, outputTokens, config.metadata);
|
|
12
|
+
}
|
|
13
|
+
await session.end();
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
specificationVersion: "v3",
|
|
17
|
+
// Non-streaming (generateText, generateObject)
|
|
18
|
+
wrapGenerate: async ({ doGenerate }) => {
|
|
19
|
+
const result = await doGenerate();
|
|
20
|
+
trackUsage(
|
|
21
|
+
result.usage.inputTokens.total,
|
|
22
|
+
result.usage.outputTokens.total
|
|
23
|
+
).catch(() => {
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
},
|
|
27
|
+
// Streaming (streamText, streamObject)
|
|
28
|
+
wrapStream: async ({ doStream }) => {
|
|
29
|
+
const { stream, ...rest } = await doStream();
|
|
30
|
+
const transformStream = new TransformStream({
|
|
31
|
+
transform(chunk, controller) {
|
|
32
|
+
if (chunk.type === "finish") {
|
|
33
|
+
trackUsage(
|
|
34
|
+
chunk.usage.inputTokens.total,
|
|
35
|
+
chunk.usage.outputTokens.total
|
|
36
|
+
).catch(() => {
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
controller.enqueue(chunk);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return { stream: stream.pipeThrough(transformStream), ...rest };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
pulseMiddleware
|
|
48
|
+
};
|
package/dist/checkout.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var f="https://pulse.beinfi.com";function h(e,t){let u=typeof e=="string"?document.querySelector(e):e;if(!u)throw new Error(`[Pulse Checkout] Container not found: ${e}`);let d=(t.baseUrl??f).replace(/\/$/,""),r=new URL(d).origin,i={};function m(o,...s){for(let a of i[o]??[])a(...s)}let n=document.createElement("iframe");n.src=`${d}/embed/pay/${t.linkId}`,n.style.width="100%",n.style.border="none",n.style.colorScheme="normal",n.setAttribute("allowtransparency","true"),n.allow="clipboard-write";function l(o){if(o.origin!==r)return;let{type:s,...a}=o.data??{};switch(s){case"pulse:ready":t.theme&&n.contentWindow?.postMessage({type:"pulse:config",theme:t.theme},r),t.onReady?.(),m("ready");break;case"pulse:resize":typeof a.height=="number"&&(n.style.height=`${a.height}px`);break;case"pulse:success":{let c=a.payment;t.onSuccess?.(c),m("success",c);break}case"pulse:error":{let c=a.error;t.onError?.(c),m("error",c);break}}}return window.addEventListener("message",l),u.appendChild(n),{unmount(){window.removeEventListener("message",l),n.remove(),t.onClose?.(),m("close")},on(o,s){i[o]||(i[o]=[]),i[o].push(s)}}}window.PulseCheckout={mount:h};function y(e){let t={};return e.dataset.themeBackground&&(t.background=e.dataset.themeBackground),e.dataset.themeForeground&&(t.foreground=e.dataset.themeForeground),e.dataset.themeCard&&(t.card=e.dataset.themeCard),e.dataset.themeAccent&&(t.accent=e.dataset.themeAccent),e.dataset.themeAccentForeground&&(t.accentForeground=e.dataset.themeAccentForeground),Object.keys(t).length>0?t:void 0}function p(){let e=document.getElementById("pulse-checkout");if(!e)return;let t=e.dataset.linkId;if(!t)return;let u=e.dataset.baseUrl,d=y(e);h(e,{linkId:t,baseUrl:u,theme:d,onReady(){e.dispatchEvent(new CustomEvent("pulse:ready"))},onSuccess(r){e.dispatchEvent(new CustomEvent("pulse:success",{detail:r}))},onError(r){e.dispatchEvent(new CustomEvent("pulse:error",{detail:r}))}})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",p):p();})();
|