@swishapp/auth-proxy 0.1.0-unstable.20260304162030
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/dist/auth-proxy.d.ts +9 -0
- package/dist/auth-proxy.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +0 -0
- package/package.json +56 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AuthProxyOptions } from "./types.js";
|
|
2
|
+
export declare const createAuthProxy: (options: AuthProxyOptions) => AuthProxy;
|
|
3
|
+
export declare class AuthProxy {
|
|
4
|
+
private readonly authenticate;
|
|
5
|
+
private readonly authToken;
|
|
6
|
+
private readonly onError?;
|
|
7
|
+
constructor({ authToken, authenticate, onError }: AuthProxyOptions);
|
|
8
|
+
createToken(request: Request): Promise<Response>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var y=Object.defineProperty;var o=(e,t)=>y(e,"name",{value:t,configurable:!0});const l="https://swish.app/api",f="2026-01",T=new Set(["2025-04","2025-07","2025-10","2026-01","2026-04","unstable"]),w=o(e=>new A(e),"createAuthProxy");class A{static{o(this,"AuthProxy")}constructor({authToken:t,authenticate:n,onError:r}){this.authToken=t,this.authenticate=n,this.onError=r}async createToken(t){try{const n=await this.authenticate(t)||null,r=typeof this.authToken=="function"?await this.authToken(t):this.authToken,s=await t.text(),a=s?JSON.parse(s):{};if(a.customer){const c=n?u(n):null,d=u(String(a.customer));if(c!==d)return new Response(JSON.stringify({error:"Unauthorized"}),{status:401,headers:{"Content-Type":"application/json"}})}const h=O(t),p=`${l}/${h}/profiles/token`,i=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:s||void 0});return new Response(i.body,{status:i.status,headers:i.headers})}catch(n){return this.onError?.(n),new Response(JSON.stringify({error:"Unauthorized",cause:n}),{status:401,headers:{"Content-Type":"application/json"}})}}}function O(e){const t=e.headers.get("swish-api-version");return t&&T.has(t)?t:f}o(O,"resolveApiVersion");function u(e){return e.startsWith("gid://")?e:`gid://shopify/Customer/${e.split("/").pop()}`}o(u,"toCustomerGid");export{A as AuthProxy,w as createAuthProxy};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./auth-proxy.js";export*from"./types.js";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface AuthProxyOptions {
|
|
2
|
+
authToken: string | ((request: Request) => Promise<string> | string);
|
|
3
|
+
authenticate: (request: Request) => Promise<string | null> | string | null;
|
|
4
|
+
onError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
export interface CreateTokenResult {
|
|
7
|
+
token: string;
|
|
8
|
+
profile: string;
|
|
9
|
+
}
|
package/dist/types.js
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@swishapp/auth-proxy",
|
|
3
|
+
"version": "0.1.0-unstable.20260304162030",
|
|
4
|
+
"description": "Server-side auth token proxy for Swish on custom storefronts.",
|
|
5
|
+
"author": "Swish",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"homepage": "https://developers.swish.app/libraries/node.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/jest": "^30.0.0",
|
|
14
|
+
"@types/node": "^24.8.0",
|
|
15
|
+
"esbuild": "^0.27.2",
|
|
16
|
+
"jest": "^30.2.0",
|
|
17
|
+
"rimraf": "^6.1.2",
|
|
18
|
+
"ts-jest": "^29.4.6",
|
|
19
|
+
"typescript": "^5.9.3"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"module": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/**/*.*",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"keywords": [
|
|
42
|
+
"swish",
|
|
43
|
+
"shopify",
|
|
44
|
+
"auth",
|
|
45
|
+
"proxy",
|
|
46
|
+
"token",
|
|
47
|
+
"node"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.build.json && node esbuild.js",
|
|
51
|
+
"dev": "node esbuild.js --watch",
|
|
52
|
+
"clean": "rimraf dist",
|
|
53
|
+
"test": "jest --passWithNoTests",
|
|
54
|
+
"test:watch": "jest --watch"
|
|
55
|
+
}
|
|
56
|
+
}
|