@timeback/sdk 0.1.8 → 0.1.9
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 +6 -6
- package/dist/{chunk-j1xdrfqj.js → chunk-5171mkp2.js} +1 -1
- package/dist/{chunk-3886xy48.js → chunk-63afdp3y.js} +6 -6
- package/dist/chunk-8gg8n8v9.js +2 -0
- package/dist/{chunk-ewsp6v3b.js → chunk-agpf1x3g.js} +5 -5
- package/dist/chunk-hnf0tart.js +2 -0
- package/dist/{chunk-rgbpvxbv.js → chunk-x9gvef7q.js} +1 -1
- package/dist/client/adapters/react/hooks/types.d.ts +34 -0
- package/dist/client/adapters/react/hooks/types.d.ts.map +1 -1
- package/dist/client/adapters/react/hooks/useTimebackVerification.d.ts +17 -5
- package/dist/client/adapters/react/hooks/useTimebackVerification.d.ts.map +1 -1
- package/dist/client/adapters/react/index.d.ts +1 -1
- package/dist/client/adapters/react/index.d.ts.map +1 -1
- package/dist/client/adapters/react/index.js +2 -2
- package/dist/client/adapters/react/provider.d.ts.map +1 -1
- package/dist/client/adapters/solid/primitives/createTimebackVerification.d.ts +3 -1
- package/dist/client/adapters/solid/primitives/createTimebackVerification.d.ts.map +1 -1
- package/dist/client/adapters/solid/primitives/createTimebackVerification.ts +55 -15
- package/dist/client/adapters/solid/types.d.ts +23 -0
- package/dist/client/adapters/solid/types.d.ts.map +1 -1
- package/dist/client/adapters/solid/types.ts +25 -0
- package/dist/client/adapters/svelte/stores/verification.d.ts +1 -1
- package/dist/client/adapters/svelte/stores/verification.d.ts.map +1 -1
- package/dist/client/adapters/svelte/stores/verification.ts +94 -12
- package/dist/client/adapters/vue/composables/useTimebackVerification.d.ts +3 -1
- package/dist/client/adapters/vue/composables/useTimebackVerification.d.ts.map +1 -1
- package/dist/client/adapters/vue/composables/useTimebackVerification.ts +59 -18
- package/dist/client/adapters/vue/types.d.ts +23 -0
- package/dist/client/adapters/vue/types.d.ts.map +1 -1
- package/dist/client/adapters/vue/types.ts +25 -0
- package/dist/client/lib/utils.d.ts +15 -0
- package/dist/client/lib/utils.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/edge.js +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/server/adapters/express.js +1 -1
- package/dist/server/adapters/native.js +1 -1
- package/dist/server/adapters/nextjs.js +1 -1
- package/dist/server/adapters/nuxt.js +1 -1
- package/dist/server/adapters/solid-start.js +1 -1
- package/dist/server/adapters/svelte-kit.js +1 -1
- package/dist/server/adapters/tanstack-start.js +1 -1
- package/dist/server/timeback.d.ts +2 -2
- package/dist/shared/constants.d.ts +13 -0
- package/dist/shared/constants.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-ahy54f2r.js +0 -2
- package/dist/chunk-qaa129bd.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../chunk-
|
|
1
|
+
import"../../chunk-x9gvef7q.js";import"../../chunk-9se82640.js";import{A as Z,B as P,y as _,z as X}from"../../chunk-5171mkp2.js";import{I as V}from"../../chunk-hnf0tart.js";import"../../chunk-07j8zre9.js";function $(C){let z=C.protocol||"http",F=C.get("host")||"localhost",J=`${z}://${F}${C.url}`,B=new Headers;for(let[M,L]of Object.entries(C.headers))if(L)B.set(M,Array.isArray(L)?L.join(", "):L);let K={method:C.method,headers:B};if(["POST","PUT","PATCH"].includes(C.method)&&C.body)K.body=JSON.stringify(C.body);return new Request(J,K)}async function Q(C,z){z.status(C.status);let F={};if(C.headers.forEach((B,K)=>{F[K]=B}),z.set(F),C.status>=300&&C.status<400){let B=C.headers.get("Location");if(B){z.redirect(B);return}}let J=await C.text();z.send(J)}function Y(C){let z=X(C);return(F,J,B)=>{let K=$(F),M=new URL(K.url).pathname;(()=>{let G=_({pathname:M,method:F.method});if(!G)return Promise.resolve(void 0);if(G==="identity.signOut")return Promise.resolve(z.identity.signOut());if(G==="identity.signIn")return z.identity.signIn(K);if(G==="identity.callback")return z.identity.callback(K);if(G==="user.me"){if(!P(z))return Promise.resolve(void 0);return z.user.me(K)}if(G==="user.verify"){if(!P(z))return Promise.resolve(void 0);return z.user.verify(K)}if(G==="activity"){if(!Z(z))return Promise.resolve(void 0);return z.activity(K)}return Promise.resolve(void 0)})().then((G)=>{if(G)return Q(G,J);B()}).catch(()=>{let G=V({error:"Internal server error"},500);return Q(G,J)})}}function j(C,z){let F=X(C);function J(B){return(K,M)=>{let L=$(K);Promise.resolve(B(L)).then((G)=>Q(G,M)).catch(()=>{let G=V({error:"Internal server error"},500);return Q(G,M)})}}if(z.get("/identity/signin",J((B)=>F.identity.signIn(B))),z.get("/identity/callback",J((B)=>F.identity.callback(B))),z.get("/identity/signout",J(()=>F.identity.signOut())),P(F))z.get("/user/me",J((B)=>F.user.me(B))),z.get("/user/verify",J((B)=>F.user.verify(B)));if(Z(F))z.post("/activity",J((B)=>F.activity(B)))}export{Y as toExpressMiddleware,j as mountExpressRoutes};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as V,B as L,y as M,z as Q}from"../../chunk-
|
|
1
|
+
import{A as V,B as L,y as M,z as Q}from"../../chunk-5171mkp2.js";import{I as K}from"../../chunk-hnf0tart.js";import"../../chunk-07j8zre9.js";function $(E){return typeof E==="object"&&E!==null&&"timeback"in E}function S(E){let{timeback:X,callbackPath:Y}=$(E)?E:{timeback:E,callbackPath:void 0},z=Q(X);return(G)=>{let Z=new URL(G.url).pathname,_=G.method,J=M({pathname:Z,method:_,callbackPath:Y});if(J==="identity.signIn")return z.identity.signIn(G);if(J==="identity.callback")return z.identity.callback(G);if(J==="identity.signOut")return Promise.resolve(z.identity.signOut());if(J==="user.me"){if(!L(z))return Promise.resolve(K({error:"Not found"},404));return z.user.me(G)}if(J==="user.verify"){if(!L(z))return Promise.resolve(K({error:"Not found"},404));return z.user.verify(G)}if(J==="activity"){if(!V(z))return Promise.resolve(K({error:"Not found"},404));return z.activity(G)}return Promise.resolve(K({error:"Not found"},404))}}export{S as toNativeHandler};
|
|
2
2
|
export{S as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as z}from"./native.js";import"../../chunk-
|
|
1
|
+
import{d as z}from"./native.js";import"../../chunk-5171mkp2.js";import"../../chunk-hnf0tart.js";import"../../chunk-07j8zre9.js";function F(B){let g=z(B);return{GET:g,POST:g,PUT:g,DELETE:g,PATCH:g}}export{F as toNextjsHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../chunk-
|
|
1
|
+
import"../../chunk-x9gvef7q.js";import"../../chunk-9se82640.js";import{A as B,B as _,x as O,y as $,z}from"../../chunk-5171mkp2.js";import{I as Y}from"../../chunk-hnf0tart.js";import"../../chunk-07j8zre9.js";function W(x){return new Promise((D,G)=>{let K=[];x.on("data",(C)=>{if(!C)return;if(C instanceof Buffer)return void K.push(C);if(typeof C==="string")return void K.push(Buffer.from(C,"utf-8"));if(C instanceof Uint8Array)return void K.push(Buffer.from(C))}),x.on("end",()=>D(Buffer.concat(K).toString("utf-8"))),x.on("error",(C)=>{if(C instanceof Error)G(C)})})}function M(x){if(x.path)return O(x.path);if(x.request){let G=x.request.url;if(G.startsWith("http://")||G.startsWith("https://"))return new URL(G).pathname;return G.split("?")[0]??"/"}return(x.node?.req?.url?.split("?")[0]??"/")||"/"}function I(x){if(!x)return;if(Array.isArray(x))return x[0]?.trim();return x.split(",")[0]?.trim()}function A(x){let D=x.url??"/";if(D.startsWith("http://")||D.startsWith("https://"))return new URL(D).href;let G=I(x.headers["x-forwarded-proto"]),K=G==="https"?"https":G==="http"?"http":"http",Q=I(x.headers["x-forwarded-host"])||x.headers.host||"localhost";return new URL(D,`${K}://${Q}`).href}function T(x){if(x.request)return x.request.url;let D=x.node?.req;if(!D)throw Error("Cannot determine URL from Nuxt event");return A(D)}function N(x){if(x.request)return x.request.method;return x.node?.req?.method??"GET"}async function V(x){if(x.request)return x.request;let D=x.node?.req;if(!D)throw Error("Cannot convert Nuxt event to Request: no request object found");let G=T(x),K=D.method??"GET",C=new Headers;for(let[S,J]of Object.entries(D.headers))if(J)C.set(S,Array.isArray(J)?J.join(", "):J);let Q={method:K,headers:C};if(["POST","PUT","PATCH","DELETE"].includes(K)){let S=await W(D);if(S)Q.body=S}return new Request(G,Q)}async function j(x){let{timeback:D,event:G,basePath:K="/api/timeback",callbackPath:C}=x,Q=M(G),S=N(G),J=z(D),X=$({pathname:Q,method:S,basePath:K,callbackPath:C});if(!X)return;if(X==="identity.signOut")return J.identity.signOut();let L=await V(G);if(X==="identity.signIn")return J.identity.signIn(L);if(X==="identity.callback")return J.identity.callback(L);if(X==="user.me"){if(!_(J))return;return J.user.me(L)}if(X==="user.verify"){if(!_(J))return;return J.user.verify(L)}if(X==="activity"){if(!B(J))return;return J.activity(L)}return}function y(x){let D=E(x)?x:{timeback:x},{timeback:G,callbackPath:K}=D,C=z(G),Q=async(S)=>{let J=M(S),X=N(S),L=$({pathname:J,method:X,callbackPath:K});if(!L)return Y({error:"Not found"},404);if(L==="identity.signOut")return C.identity.signOut();let Z=await V(S);if(L==="identity.signIn")return C.identity.signIn(Z);if(L==="identity.callback")return C.identity.callback(Z);if(L==="user.me"){if(!_(C))return Y({error:"Not found"},404);return C.user.me(Z)}if(L==="user.verify"){if(!_(C))return Y({error:"Not found"},404);return C.user.verify(Z)}if(L==="activity"){if(!B(C))return Y({error:"Not found"},404);return C.activity(Z)}return Y({error:"Not found"},404)};return{GET:Q,POST:Q,PUT:Q,DELETE:Q,PATCH:Q}}function E(x){return typeof x==="object"&&x!==null&&"timeback"in x}export{y as toNuxtHandler,j as nuxtHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../chunk-
|
|
1
|
+
import"../../chunk-x9gvef7q.js";import"../../chunk-9se82640.js";import{A as O,B as I,y as L,z as N}from"../../chunk-5171mkp2.js";import{I as G}from"../../chunk-hnf0tart.js";import"../../chunk-07j8zre9.js";function Z(J){let B=N(J),E=(C)=>{let D=new URL(C.request.url).pathname,K=C.request.method,z=L({pathname:D,method:K});if(!z)return G({error:"Not found"},404);if(z==="identity.signOut")return B.identity.signOut();if(z==="identity.signIn")return B.identity.signIn(C.request);if(z==="identity.callback")return B.identity.callback(C.request);if(z==="user.me"){if(!I(B))return G({error:"Not found"},404);return B.user.me(C.request)}if(z==="user.verify"){if(!I(B))return G({error:"Not found"},404);return B.user.verify(C.request)}if(z==="activity"){if(!O(B))return G({error:"Not found"},404);return B.activity(C.request)}return G({error:"Not found"},404)};return{GET:E,POST:E,PUT:E,DELETE:E,PATCH:E}}function _(J){let{timeback:B,event:E,basePath:C="/api/timeback",callbackPath:Q}=J,D=E.request,K=new URL(D.url),z=N(B),V=K.pathname,W=D.method,F=L({pathname:V,method:W,basePath:C,callbackPath:Q});if(!F)return;if(F==="identity.signOut")return z.identity.signOut();if(F==="identity.signIn")return z.identity.signIn(D);if(F==="identity.callback")return z.identity.callback(D);if(F==="user.me"){if(!I(z))return;return z.user.me(D)}if(F==="user.verify"){if(!I(z))return;return z.user.verify(D)}if(F==="activity"){if(!O(z))return;return z.activity(D)}return}export{Z as toSolidStartHandler,_ as solidStartHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as Z}from"./native.js";import{A as Y,B as V,y as W,z as X}from"../../chunk-
|
|
1
|
+
import{d as Z}from"./native.js";import{A as Y,B as V,y as W,z as X}from"../../chunk-5171mkp2.js";import"../../chunk-hnf0tart.js";import"../../chunk-07j8zre9.js";async function $(M){let{timeback:F,event:z,resolve:D,building:Q=!1,basePath:_="/api/timeback",callbackPath:C}=M;if(Q)return D(z);let{url:E,request:L}=z,B=X(F),G=E.pathname,I=L.method,J=W({pathname:G,method:I,basePath:_,callbackPath:C});if(!J)return D(z);if(J==="identity.signOut")return B.identity.signOut();if(J==="identity.signIn")return await B.identity.signIn(L);if(J==="identity.callback")return await B.identity.callback(L);if(J==="user.me"){if(!V(B))return D(z);return await B.user.me(L)}if(J==="user.verify"){if(!V(B))return D(z);return await B.user.verify(L)}if(J==="activity"){if(!Y(B))return D(z);return await B.activity(L)}return D(z)}function j(M){let F=Z(M),z=(D)=>{return(Q)=>D(Q.request)};return{GET:z(F),POST:z(F),PUT:z(F),DELETE:z(F),PATCH:z(F)}}export{j as toSvelteKitHandler,$ as svelteKitHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../chunk-
|
|
1
|
+
import"../../chunk-x9gvef7q.js";import"../../chunk-9se82640.js";import{A as I,B as E,y as F,z as G}from"../../chunk-5171mkp2.js";import{I as B}from"../../chunk-hnf0tart.js";import"../../chunk-07j8zre9.js";function Q(C){let J=V(C)?C:{timeback:C},{timeback:K,callbackPath:L}=J,q=G(K),D=(x)=>{let M=new URL(x.request.url).pathname,N=x.request.method,z=F({pathname:M,method:N,callbackPath:L});if(!z)return B({error:"Not found"},404);if(z==="identity.signOut")return q.identity.signOut();if(z==="identity.signIn")return q.identity.signIn(x.request);if(z==="identity.callback")return q.identity.callback(x.request);if(z==="user.me"){if(!E(q))return B({error:"Not found"},404);return q.user.me(x.request)}if(z==="user.verify"){if(!E(q))return B({error:"Not found"},404);return q.user.verify(x.request)}if(z==="activity"){if(!I(q))return B({error:"Not found"},404);return q.activity(x.request)}return B({error:"Not found"},404)};return{GET:D,POST:D,PUT:D,DELETE:D,PATCH:D}}function V(C){return"timeback"in C}var Z=Q;export{Q as toTanStackStartHandler,Z as tanstackStartHandler};
|
|
@@ -33,8 +33,8 @@ import type { TimebackConfig, TimebackInstance } from './types';
|
|
|
33
33
|
* },
|
|
34
34
|
* identity: {
|
|
35
35
|
* mode: 'sso',
|
|
36
|
-
* clientId: process.env.
|
|
37
|
-
* clientSecret: process.env.
|
|
36
|
+
* clientId: process.env.TIMEBACK_SSO_CLIENT_ID!,
|
|
37
|
+
* clientSecret: process.env.TIMEBACK_SSO_CLIENT_SECRET!,
|
|
38
38
|
* onCallbackSuccess: async ({ user, state, redirect }) => {
|
|
39
39
|
* // user.id is the timebackId (canonical stable identifier)
|
|
40
40
|
* await setSession({ id: user.id, email: user.email })
|
|
@@ -22,4 +22,17 @@ export declare const ROUTES: {
|
|
|
22
22
|
* Example: `10 / 10` can become `0.9999999999999999` due to IEEE754 rounding.
|
|
23
23
|
*/
|
|
24
24
|
export declare const PERFECT_ACCURACY_THRESHOLD = 0.999999;
|
|
25
|
+
/**
|
|
26
|
+
* Default number of retry attempts for verification.
|
|
27
|
+
*
|
|
28
|
+
* Retries help handle race conditions where the user may not be
|
|
29
|
+
* fully set up in the backend when verification first runs.
|
|
30
|
+
*/
|
|
31
|
+
export declare const DEFAULT_RETRY_ATTEMPTS = 3;
|
|
32
|
+
/**
|
|
33
|
+
* Default retry delays in milliseconds (exponential backoff).
|
|
34
|
+
*
|
|
35
|
+
* Each index corresponds to the delay before that retry attempt.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_RETRY_DELAYS_MS: readonly [100, 300, 1000];
|
|
25
38
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,gDAAgD;AAChD,eAAO,MAAM,iBAAiB,kBAAkB,CAAA;AAEhD,sBAAsB;AACtB,eAAO,MAAM,MAAM;;;;;;;;;;;CAWT,CAAA;AAEV;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,gDAAgD;AAChD,eAAO,MAAM,iBAAiB,kBAAkB,CAAA;AAEhD,sBAAsB;AACtB,eAAO,MAAM,MAAM;;;;;;;;;;;CAWT,CAAA;AAEV;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,WAAW,CAAA;AAElD;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAA;AAEvC;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,2BAA4B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timeback/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Timeback SDK for frontend and backend integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -79,19 +79,19 @@
|
|
|
79
79
|
"test:e2e": "bun test --no-env-file e2e.test.ts"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@timeback/core": "0.1.
|
|
82
|
+
"@timeback/core": "0.1.4",
|
|
83
83
|
"c12": "^3.3.3",
|
|
84
84
|
"zod": "^4.2.1"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@timeback/caliper": "0.1.
|
|
88
|
-
"@timeback/edubridge": "0.1.
|
|
87
|
+
"@timeback/caliper": "0.1.3",
|
|
88
|
+
"@timeback/edubridge": "0.1.3",
|
|
89
89
|
"@timeback/internal-cli-infra": "0.0.0",
|
|
90
90
|
"@timeback/internal-client-infra": "0.0.0",
|
|
91
91
|
"@timeback/internal-logger": "0.0.0",
|
|
92
92
|
"@timeback/internal-test": "0.0.0",
|
|
93
93
|
"@timeback/internal-utils": "0.0.0",
|
|
94
|
-
"@timeback/oneroster": "0.1.
|
|
94
|
+
"@timeback/oneroster": "0.1.5",
|
|
95
95
|
"@timeback/types": "0.0.0",
|
|
96
96
|
"@types/bun": "latest",
|
|
97
97
|
"@types/express": "^5.0.6",
|
package/dist/chunk-ahy54f2r.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
class H{params;sendActivity;_startedAt;_isPaused=!1;_pausedAt;_totalPausedMs=0;_ended=!1;constructor(q,J){this.params=q;this.sendActivity=J;this._startedAt=new Date}get startedAt(){return this._startedAt}get isPaused(){return this._isPaused}get elapsedMs(){if(this._ended)return 0;let q=new Date,J=q.getTime()-this._startedAt.getTime()-this._totalPausedMs;if(this._isPaused&&this._pausedAt)J-=q.getTime()-this._pausedAt.getTime();return Math.max(0,J)}_buildPayload(q){let J=new Date,N,$;if(q.time)N=Math.max(0,Math.round(q.time.active)),$=Math.max(0,Math.round(q.time.inactive??0));else $=this._totalPausedMs+(this._isPaused&&this._pausedAt?J.getTime()-this._pausedAt.getTime():0),N=Math.max(0,J.getTime()-this._startedAt.getTime()-$);let X=q.totalQuestions!==void 0,z=q.correctQuestions!==void 0;if(X!==z)throw Error("Invalid activity metrics: totalQuestions and correctQuestions must be provided together.");if(X&&z&&q.correctQuestions>q.totalQuestions)throw Error("Invalid activity metrics: correctQuestions cannot exceed totalQuestions.");let x={...X?{totalQuestions:q.totalQuestions}:{},...z?{correctQuestions:q.correctQuestions}:{},...q.xpEarned===void 0?{}:{xpEarned:q.xpEarned},...q.masteredUnits===void 0?{}:{masteredUnits:q.masteredUnits}};return{id:this.params.id,name:this.params.name,course:this.params.course,startedAt:this._startedAt.toISOString(),endedAt:J.toISOString(),elapsedMs:N,pausedMs:$,metrics:x,...q.pctComplete===void 0?{}:{pctComplete:q.pctComplete}}}pause(){if(this._isPaused||this._ended)return;this._isPaused=!0,this._pausedAt=new Date}resume(){if(!this._isPaused||this._ended||!this._pausedAt)return;this._totalPausedMs+=new Date().getTime()-this._pausedAt.getTime(),this._isPaused=!1,this._pausedAt=void 0}async end(q){if(this._ended)return;if(this._ended=!0,this._isPaused&&this._pausedAt)this._totalPausedMs+=new Date().getTime()-this._pausedAt.getTime(),this._isPaused=!1,this._pausedAt=void 0;let J=this._buildPayload(q);await this.sendActivity(J)}}var W="/api/timeback",Y={ACTIVITY:"/activity",IDENTITY:{SIGNIN:"/identity/signin",SIGNOUT:"/identity/signout",CALLBACK:"/identity/callback"},USER:{ME:"/user/me",VERIFY:"/user/verify"}};function _(){if(!(typeof globalThis>"u"?void 0:globalThis.fetch))return;return(J,N)=>globalThis.fetch(J,N)}function j(){return typeof window<"u"}function K(){if(!j())return;return`${window.location.origin}${W}`}class Z{sendActivity;constructor(q){this.sendActivity=q}start(q){return new H(q,this.sendActivity)}}class G{getBaseURL;constructor(q){this.getBaseURL=q}signIn(){if(!j())throw Error("signIn() requires a browser environment");window.location.href=`${this.getBaseURL()}${Y.IDENTITY.SIGNIN}`}}class Q{getBaseURL;fetchImpl;constructor(q,J){this.getBaseURL=q;this.fetchImpl=J}async fetch(){if(!j())throw Error("user.fetch() requires a browser environment");let q=await this.fetchImpl(`${this.getBaseURL()}${Y.USER.ME}`,{method:"GET",credentials:"include"});if(!q.ok){let J=await q.json().catch(()=>({error:"Unknown error"}));throw Error(J.error??"Failed to fetch user profile")}return q.json()}async verify(){if(!j())throw Error("user.verify() requires a browser environment");let q=await this.fetchImpl(`${this.getBaseURL()}${Y.USER.VERIFY}`,{method:"GET",credentials:"include"});if(!q.ok){let N=await q.json().catch(()=>({error:"Unknown error"}));throw Error(N.error??"Failed to verify Timeback user")}let J=await q.json();if(J.verified&&J.timebackId)return{verified:!0,timebackId:J.timebackId};return{verified:!1}}}class V{activity;auth;user;_baseURL;_fetch;constructor(q={}){this._baseURL=q.baseURL;let J=q.fetch??_();if(!J)throw Error("TimebackClient requires a fetch implementation. Provide `fetch` in the constructor config for non-browser runtimes.");let N=q.plugins,$=Array.isArray(N)?N:N?[N]:[];this._fetch=$.reduce((X,z)=>z.wrapFetch(X),J),this.activity=new Z((X)=>this.sendActivity(X)),this.auth=new G(()=>this.baseURL),this.user=new Q(()=>this.baseURL,this._fetch)}get baseURL(){if(!this._baseURL){let q=K();if(!q)throw Error("Timeback client requires a browser environment for default baseURL. Provide an explicit baseURL for server-side usage.");this._baseURL=q}return this._baseURL}async sendActivity(q){let J=await this._fetch(`${this.baseURL}${Y.ACTIVITY}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(q),credentials:"include"});if(!J.ok){let N=await J.json().catch(()=>({error:"Unknown error"}));throw Error(N.error??"Failed to send activity")}}}function d(q={}){let J=q.baseURL??K();return new V({baseURL:J,fetch:q.fetch,plugins:q.plugins})}
|
|
2
|
-
export{H as a,V as b,d as c};
|
package/dist/chunk-qaa129bd.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{createHash as A}from"node:crypto";function C(k){return{course:k,component:`${k}-component`,resource:`${k}-resource`,componentResource:`${k}-cr`}}function D(k){return A("sha256").update(k).digest("hex")}function F(k){if(k==="local"||k==="staging")return"staging";return"production"}function G(k){if(k==="production"||k==="local"||k==="staging")return k;return"staging"}function J(k,q=200,w){let z=new Headers(w);return z.set("Content-Type","application/json"),new Response(JSON.stringify(k),{status:q,headers:z})}function K(k,q){let w=new Headers(q);return w.set("Location",k),new Response(null,{status:302,headers:w})}function L(k){let q=JSON.stringify(k);return btoa(q).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function M(k){let q=k.replace(/-/g,"+").replace(/_/g,"/"),w=atob(q);return JSON.parse(w)}var O={ACTIVITY:"/activity",IDENTITY:{SIGNIN:"/identity/signin",SIGNOUT:"/identity/signout",CALLBACK:"/identity/callback"},USER:{ME:"/user/me",VERIFY:"/user/verify"}},P=0.999999;
|
|
2
|
-
export{O as C,P as D,C as E,D as F,F as G,G as H,J as I,K as J,L as K,M as L};
|