@hasura/promptql 2.0.0-alpha.3 → 2.0.0-alpha.30
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 +0 -1
- package/biome.json +11 -4
- package/dist/auth/index.d.mts +35 -0
- package/dist/auth/index.d.ts +35 -0
- package/dist/auth/index.js +1 -0
- package/dist/auth/index.mjs +1 -0
- package/dist/chunk-YCHA4U67.mjs +1 -0
- package/dist/graphql-DNHSh7_M.d.mts +2438 -0
- package/dist/graphql-DNHSh7_M.d.ts +2438 -0
- package/dist/index.d.mts +2362 -3196
- package/dist/index.d.ts +2362 -3196
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +12 -10
- package/tsconfig.json +29 -5
package/README.md
CHANGED
package/biome.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/2.
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.13/schema.json",
|
|
3
3
|
"root": false,
|
|
4
4
|
"files": {
|
|
5
|
-
"includes": [
|
|
5
|
+
"includes": [
|
|
6
|
+
"**/*.ts",
|
|
7
|
+
"**/*.gql",
|
|
8
|
+
"!src/generated/*",
|
|
9
|
+
"!dist/**/*"
|
|
10
|
+
]
|
|
6
11
|
},
|
|
7
|
-
"extends": [
|
|
8
|
-
|
|
12
|
+
"extends": [
|
|
13
|
+
"../biome-config/base.json"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { E as EnrichTokenOutput } from '../graphql-DNHSh7_M.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Constructor options for a PromptQL authenticator.
|
|
6
|
+
*/
|
|
7
|
+
type PromptQLAuthTokenGeneratorOptions = {
|
|
8
|
+
authHost?: string;
|
|
9
|
+
promptqlGraphQLUrl: string;
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
projectId?: string;
|
|
12
|
+
fetch?: typeof fetch;
|
|
13
|
+
};
|
|
14
|
+
declare function createPromptQLAuthTokenGenerator(options: PromptQLAuthTokenGeneratorOptions): () => Promise<string>;
|
|
15
|
+
declare const enrichToken: (promptqlGraphQLUrl: string, token: string, projectId?: string, customFetch?: typeof fetch) => Promise<string>;
|
|
16
|
+
|
|
17
|
+
type LuxAuthPromptQLTokenSuccessResponse = {
|
|
18
|
+
status: "success";
|
|
19
|
+
expiry: string;
|
|
20
|
+
token: string;
|
|
21
|
+
};
|
|
22
|
+
type LuxAuthPromptQLTokenFailedResponse = {
|
|
23
|
+
error: string;
|
|
24
|
+
status: "failure";
|
|
25
|
+
};
|
|
26
|
+
declare function isLuxAuthPromptQLTokenFailedResponse(input: unknown): input is LuxAuthPromptQLTokenFailedResponse;
|
|
27
|
+
declare function isLuxAuthPromptQLTokenSuccessResponse(input: unknown): input is LuxAuthPromptQLTokenSuccessResponse;
|
|
28
|
+
declare function isEnrichTokenMutationResponse(input: unknown): input is {
|
|
29
|
+
data?: {
|
|
30
|
+
enrich_token: EnrichTokenOutput;
|
|
31
|
+
};
|
|
32
|
+
errors?: GraphQLError[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { type LuxAuthPromptQLTokenSuccessResponse, type PromptQLAuthTokenGeneratorOptions, createPromptQLAuthTokenGenerator, enrichToken, isEnrichTokenMutationResponse, isLuxAuthPromptQLTokenFailedResponse, isLuxAuthPromptQLTokenSuccessResponse };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { E as EnrichTokenOutput } from '../graphql-DNHSh7_M.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Constructor options for a PromptQL authenticator.
|
|
6
|
+
*/
|
|
7
|
+
type PromptQLAuthTokenGeneratorOptions = {
|
|
8
|
+
authHost?: string;
|
|
9
|
+
promptqlGraphQLUrl: string;
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
projectId?: string;
|
|
12
|
+
fetch?: typeof fetch;
|
|
13
|
+
};
|
|
14
|
+
declare function createPromptQLAuthTokenGenerator(options: PromptQLAuthTokenGeneratorOptions): () => Promise<string>;
|
|
15
|
+
declare const enrichToken: (promptqlGraphQLUrl: string, token: string, projectId?: string, customFetch?: typeof fetch) => Promise<string>;
|
|
16
|
+
|
|
17
|
+
type LuxAuthPromptQLTokenSuccessResponse = {
|
|
18
|
+
status: "success";
|
|
19
|
+
expiry: string;
|
|
20
|
+
token: string;
|
|
21
|
+
};
|
|
22
|
+
type LuxAuthPromptQLTokenFailedResponse = {
|
|
23
|
+
error: string;
|
|
24
|
+
status: "failure";
|
|
25
|
+
};
|
|
26
|
+
declare function isLuxAuthPromptQLTokenFailedResponse(input: unknown): input is LuxAuthPromptQLTokenFailedResponse;
|
|
27
|
+
declare function isLuxAuthPromptQLTokenSuccessResponse(input: unknown): input is LuxAuthPromptQLTokenSuccessResponse;
|
|
28
|
+
declare function isEnrichTokenMutationResponse(input: unknown): input is {
|
|
29
|
+
data?: {
|
|
30
|
+
enrich_token: EnrichTokenOutput;
|
|
31
|
+
};
|
|
32
|
+
errors?: GraphQLError[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { type LuxAuthPromptQLTokenSuccessResponse, type PromptQLAuthTokenGeneratorOptions, createPromptQLAuthTokenGenerator, enrichToken, isEnrichTokenMutationResponse, isLuxAuthPromptQLTokenFailedResponse, isLuxAuthPromptQLTokenSuccessResponse };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var y=(e,r)=>{for(var a in r)c(e,a,{get:r[a],enumerable:!0})},w=(e,r,a,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of T(r))!x.call(e,t)&&t!==a&&c(e,t,{get:()=>r[t],enumerable:!(o=k(r,t))||o.enumerable});return e};var g=e=>w(c({},"__esModule",{value:!0}),e);var P={};y(P,{createPromptQLAuthTokenGenerator:()=>L,enrichToken:()=>f,isEnrichTokenMutationResponse:()=>p,isLuxAuthPromptQLTokenFailedResponse:()=>u,isLuxAuthPromptQLTokenSuccessResponse:()=>h});module.exports=g(P);function m(e){return e=e?e.trim():"",e?e[e.length-1]==="/"?e.slice(0,e.length-1):e:""}function u(e){return e!=null&&typeof e=="object"&&"status"in e&&e.status==="failure"}function h(e){return e!=null&&typeof e=="object"&&"status"in e&&e.status==="success"&&"token"in e}function p(e){return e!=null&&typeof e=="object"&&("data"in e&&!!e.data&&typeof e.data=="object"&&"enrich_token"in e.data&&!!e.data.enrich_token&&typeof e.data.enrich_token=="object"&&"userDirectoryJWT"in e.data.enrich_token||"errors"in e&&Array.isArray(e.errors))}function L(e){let a=`${m(e.authHost)||"https://auth.pro.hasura.io"}/ddn/promptql/token`,o={token:"",expiry:new Date(0)},t=e.fetch||fetch,i=async()=>{let n=await t(a,{method:"POST",headers:e.headers});switch(n.status){case 200:{let s=await n.json();if(h(s))return s;throw new Error("malformed token response")}case 401:{let s=await n.json();throw u(s)?new Error(s?.error||n.statusText):new Error(n.statusText)}default:{let s=await n.text();throw new Error(s)}}};return async()=>{if(o.expiry.getTime()<=Date.now()+1e3){let n=await i(),s=await f(e.promptqlGraphQLUrl,n.token,e.projectId,t);o.token=s;let d=new Date(n.expiry);if(Number.isNaN(d.getTime())){let l=new Date;l.setHours(1),o.expiry=l}else o.expiry=d}return o.token}}var f=async(e,r,a,o=fetch)=>{let t=await o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:"mutation EnrichToken($luxJWT: String!, $projectId: uuid) { enrich_token(luxJWT: $luxJWT, projectId: $projectId) { userDirectoryJWT }}",variables:{luxJWT:r,projectId:a},operationName:"EnrichToken"})});switch(t.status){case 200:{let i=await t.json();if(!p(i)||!i.data?.enrich_token?.userDirectoryJWT)throw new Error(`malformed promptql token response: ${JSON.stringify(i)}`);return i.data.enrich_token.userDirectoryJWT}default:{let i=await t.text();throw new Error(i)}}};0&&(module.exports={createPromptQLAuthTokenGenerator,enrichToken,isEnrichTokenMutationResponse,isLuxAuthPromptQLTokenFailedResponse,isLuxAuthPromptQLTokenSuccessResponse});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as a,d as b,e as c,f as d,g as e}from"../chunk-YCHA4U67.mjs";export{d as createPromptQLAuthTokenGenerator,e as enrichToken,c as isEnrichTokenMutationResponse,a as isLuxAuthPromptQLTokenFailedResponse,b as isLuxAuthPromptQLTokenSuccessResponse};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function h(e){return e=e?e.trim():"",e?e[e.length-1]==="/"?e.slice(0,e.length-1):e:""}function f(e){if(e==null)return null;try{Number.parseInt(e)}catch{throw new Error("invalid threadEventId")}return e}function p(e){return e!=null&&typeof e=="object"&&"status"in e&&e.status==="failure"}function d(e){return e!=null&&typeof e=="object"&&"status"in e&&e.status==="success"&&"token"in e}function l(e){return e!=null&&typeof e=="object"&&("data"in e&&!!e.data&&typeof e.data=="object"&&"enrich_token"in e.data&&!!e.data.enrich_token&&typeof e.data.enrich_token=="object"&&"userDirectoryJWT"in e.data.enrich_token||"errors"in e&&Array.isArray(e.errors))}function w(e){let a=`${h(e.authHost)||"https://auth.pro.hasura.io"}/ddn/promptql/token`,n={token:"",expiry:new Date(0)},s=e.fetch||fetch,o=async()=>{let r=await s(a,{method:"POST",headers:e.headers});switch(r.status){case 200:{let t=await r.json();if(d(t))return t;throw new Error("malformed token response")}case 401:{let t=await r.json();throw p(t)?new Error(t?.error||r.statusText):new Error(r.statusText)}default:{let t=await r.text();throw new Error(t)}}};return async()=>{if(n.expiry.getTime()<=Date.now()+1e3){let r=await o(),t=await m(e.promptqlGraphQLUrl,r.token,e.projectId,s);n.token=t;let c=new Date(r.expiry);if(Number.isNaN(c.getTime())){let u=new Date;u.setHours(1),n.expiry=u}else n.expiry=c}return n.token}}var m=async(e,i,a,n=fetch)=>{let s=await n(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:"mutation EnrichToken($luxJWT: String!, $projectId: uuid) { enrich_token(luxJWT: $luxJWT, projectId: $projectId) { userDirectoryJWT }}",variables:{luxJWT:i,projectId:a},operationName:"EnrichToken"})});switch(s.status){case 200:{let o=await s.json();if(!l(o)||!o.data?.enrich_token?.userDirectoryJWT)throw new Error(`malformed promptql token response: ${JSON.stringify(o)}`);return o.data.enrich_token.userDirectoryJWT}default:{let o=await s.text();throw new Error(o)}}};export{h as a,f as b,p as c,d,l as e,w as f,m as g};
|