@opengovsg/refx-ts-sdk 0.0.0-develop-alpha-1762412839 → 0.0.0-develop-alpha-1762754615

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 CHANGED
@@ -165,24 +165,6 @@ const client = new ReferralExchangeClient({
165
165
  });
166
166
  ```
167
167
 
168
- ### JWT Authenticated Client
169
-
170
- If you need to authenticate requests by signing short-lived JWTs locally, use the `ReferralExchangeJwtClient`. It
171
- accepts a PEM-encoded ES256 private key and the API key name to embed as the issuer claim. Each request automatically
172
- receives a freshly signed token (15 second TTL) in the `Authorization` header.
173
-
174
- ```typescript
175
- import { ReferralExchangeJwtClient } from "@opengovsg/refx-ts-sdk";
176
-
177
- const client = new ReferralExchangeJwtClient({
178
- privateKey: process.env.REFX_PRIVATE_KEY!,
179
- apiKeyName: process.env.REFX_API_KEY_NAME!,
180
- environment: "Production", // or pass baseUrl
181
- });
182
-
183
- const offerings = await client.offerings.list();
184
- ```
185
-
186
168
  ## Contributing
187
169
 
188
170
  While we value open-source contributions to this SDK, this library is generated programmatically.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * as ReferralExchange from "./api";
2
2
  export { ReferralExchangeClient } from "./Client";
3
- export { ReferralExchangeJwtClient } from "./wrapper/ReferralExchangeJwtClient";
4
3
  export { ReferralExchangeEnvironment } from "./environments";
5
4
  export { ReferralExchangeError, ReferralExchangeTimeoutError } from "./errors";
package/dist/index.js CHANGED
@@ -33,12 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ReferralExchangeTimeoutError = exports.ReferralExchangeError = exports.ReferralExchangeEnvironment = exports.ReferralExchangeJwtClient = exports.ReferralExchangeClient = exports.ReferralExchange = void 0;
36
+ exports.ReferralExchangeTimeoutError = exports.ReferralExchangeError = exports.ReferralExchangeEnvironment = exports.ReferralExchangeClient = exports.ReferralExchange = void 0;
37
37
  exports.ReferralExchange = __importStar(require("./api"));
38
38
  var Client_1 = require("./Client");
39
39
  Object.defineProperty(exports, "ReferralExchangeClient", { enumerable: true, get: function () { return Client_1.ReferralExchangeClient; } });
40
- var ReferralExchangeJwtClient_1 = require("./wrapper/ReferralExchangeJwtClient");
41
- Object.defineProperty(exports, "ReferralExchangeJwtClient", { enumerable: true, get: function () { return ReferralExchangeJwtClient_1.ReferralExchangeJwtClient; } });
42
40
  var environments_1 = require("./environments");
43
41
  Object.defineProperty(exports, "ReferralExchangeEnvironment", { enumerable: true, get: function () { return environments_1.ReferralExchangeEnvironment; } });
44
42
  var errors_1 = require("./errors");
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * as ReferralExchange from "./api";
2
2
  export { ReferralExchangeClient } from "./Client";
3
- export { ReferralExchangeJwtClient } from "./wrapper/ReferralExchangeJwtClient";
4
3
  export { ReferralExchangeEnvironment } from "./environments";
5
4
  export { ReferralExchangeError, ReferralExchangeTimeoutError } from "./errors";
package/index.js CHANGED
@@ -33,12 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ReferralExchangeTimeoutError = exports.ReferralExchangeError = exports.ReferralExchangeEnvironment = exports.ReferralExchangeJwtClient = exports.ReferralExchangeClient = exports.ReferralExchange = void 0;
36
+ exports.ReferralExchangeTimeoutError = exports.ReferralExchangeError = exports.ReferralExchangeEnvironment = exports.ReferralExchangeClient = exports.ReferralExchange = void 0;
37
37
  exports.ReferralExchange = __importStar(require("./api"));
38
38
  var Client_1 = require("./Client");
39
39
  Object.defineProperty(exports, "ReferralExchangeClient", { enumerable: true, get: function () { return Client_1.ReferralExchangeClient; } });
40
- var ReferralExchangeJwtClient_1 = require("./wrapper/ReferralExchangeJwtClient");
41
- Object.defineProperty(exports, "ReferralExchangeJwtClient", { enumerable: true, get: function () { return ReferralExchangeJwtClient_1.ReferralExchangeJwtClient; } });
42
40
  var environments_1 = require("./environments");
43
41
  Object.defineProperty(exports, "ReferralExchangeEnvironment", { enumerable: true, get: function () { return environments_1.ReferralExchangeEnvironment; } });
44
42
  var errors_1 = require("./errors");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengovsg/refx-ts-sdk",
3
- "version": "0.0.0-develop-alpha-1762412839",
3
+ "version": "0.0.0-develop-alpha-1762754615",
4
4
  "private": false,
5
5
  "repository": "https://github.com/opengovsg/refer-ts-sdk",
6
6
  "main": "./index.js",
@@ -9,14 +9,12 @@
9
9
  "format": "prettier . --write --ignore-unknown",
10
10
  "build": "tsc",
11
11
  "prepack": "cp -rv dist/. .",
12
- "pretest": "yarn build",
13
12
  "test": "jest"
14
13
  },
15
14
  "dependencies": {
16
15
  "url-join": "4.0.1",
17
16
  "form-data": "^4.0.0",
18
17
  "formdata-node": "^6.0.3",
19
- "jsonwebtoken": "^9.0.2",
20
18
  "node-fetch": "^2.7.0",
21
19
  "qs": "^6.13.1",
22
20
  "readable-stream": "^4.5.2"
@@ -25,7 +23,6 @@
25
23
  "@types/url-join": "4.0.1",
26
24
  "@types/qs": "^6.9.17",
27
25
  "@types/node-fetch": "^2.6.12",
28
- "@types/jsonwebtoken": "^9.0.7",
29
26
  "@types/readable-stream": "^4.0.18",
30
27
  "webpack": "^5.97.1",
31
28
  "ts-loader": "^9.5.1",
@@ -40,7 +37,6 @@
40
37
  "browser": {
41
38
  "fs": false,
42
39
  "os": false,
43
- "path": false,
44
- "jsonwebtoken": "./dist/browser/jsonwebtoken-stub.js"
40
+ "path": false
45
41
  }
46
42
  }
@@ -1,5 +0,0 @@
1
- interface JsonWebTokenStub {
2
- sign: () => never;
3
- }
4
- declare const jsonwebtokenStub: JsonWebTokenStub;
5
- export default jsonwebtokenStub;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const browserOnlyMessage = "ReferralExchangeJwtClient is only supported in Node.js environments. " +
4
- "The browser build intentionally excludes the jsonwebtoken dependency.";
5
- const jsonwebtokenStub = {
6
- sign() {
7
- throw new Error(browserOnlyMessage);
8
- },
9
- };
10
- exports.default = jsonwebtokenStub;
@@ -1,5 +0,0 @@
1
- interface JsonWebTokenStub {
2
- sign: () => never;
3
- }
4
- declare const jsonwebtokenStub: JsonWebTokenStub;
5
- export default jsonwebtokenStub;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const browserOnlyMessage = "ReferralExchangeJwtClient is only supported in Node.js environments. " +
4
- "The browser build intentionally excludes the jsonwebtoken dependency.";
5
- const jsonwebtokenStub = {
6
- sign() {
7
- throw new Error(browserOnlyMessage);
8
- },
9
- };
10
- exports.default = jsonwebtokenStub;
@@ -1,10 +0,0 @@
1
- import { ReferralExchangeClient } from "../Client";
2
- export declare namespace ReferralExchangeJwtClient {
3
- interface Options extends Omit<ReferralExchangeClient.Options, "fetcher" | "apiKey"> {
4
- privateKey: string;
5
- apiKeyName: string;
6
- }
7
- }
8
- export declare class ReferralExchangeJwtClient extends ReferralExchangeClient {
9
- constructor(options: ReferralExchangeJwtClient.Options);
10
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ReferralExchangeJwtClient = void 0;
27
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
28
- const Client_1 = require("../Client");
29
- const Fetcher_1 = require("../core/fetcher/Fetcher");
30
- const JWT_TTL_SECONDS = 15;
31
- class ReferralExchangeJwtClient extends Client_1.ReferralExchangeClient {
32
- constructor(options) {
33
- const { privateKey, apiKeyName } = options, baseOptions = __rest(options, ["privateKey", "apiKeyName"]);
34
- const signer = new JwtSigner({ privateKey, issuer: apiKeyName });
35
- const fetcher = createJwtFetcher(signer);
36
- super(Object.assign(Object.assign({}, baseOptions), { fetcher }));
37
- }
38
- }
39
- exports.ReferralExchangeJwtClient = ReferralExchangeJwtClient;
40
- class JwtSigner {
41
- constructor({ privateKey, issuer }) {
42
- this.privateKey = privateKey;
43
- this.issuer = issuer;
44
- }
45
- getToken() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const nowSeconds = Math.floor(Date.now() / 1000);
48
- if (this.cachedToken != null && nowSeconds < this.cachedToken.expiresAtEpochSeconds - 1) {
49
- return this.cachedToken.token;
50
- }
51
- const { token, expiresAtEpochSeconds } = createSignedJwt({
52
- privateKey: this.privateKey,
53
- issuer: this.issuer,
54
- });
55
- this.cachedToken = { token, expiresAtEpochSeconds };
56
- return token;
57
- });
58
- }
59
- }
60
- function createJwtFetcher(signer) {
61
- return (args) => __awaiter(this, void 0, void 0, function* () {
62
- var _a;
63
- const token = yield signer.getToken();
64
- const headers = Object.assign({}, ((_a = args.headers) !== null && _a !== void 0 ? _a : {}));
65
- headers.Authorization = `Bearer ${token}`;
66
- return (0, Fetcher_1.fetcherImpl)(Object.assign(Object.assign({}, args), { headers }));
67
- });
68
- }
69
- function createSignedJwt({ privateKey, issuer }) {
70
- const issuedAt = Math.floor(Date.now() / 1000);
71
- const expiresAtEpochSeconds = issuedAt + JWT_TTL_SECONDS;
72
- const token = jsonwebtoken_1.default.sign({}, privateKey, {
73
- algorithm: "ES256",
74
- issuer,
75
- expiresIn: JWT_TTL_SECONDS,
76
- });
77
- return {
78
- token,
79
- expiresAtEpochSeconds,
80
- };
81
- }
@@ -1,10 +0,0 @@
1
- import { ReferralExchangeClient } from "../Client";
2
- export declare namespace ReferralExchangeJwtClient {
3
- interface Options extends Omit<ReferralExchangeClient.Options, "fetcher" | "apiKey"> {
4
- privateKey: string;
5
- apiKeyName: string;
6
- }
7
- }
8
- export declare class ReferralExchangeJwtClient extends ReferralExchangeClient {
9
- constructor(options: ReferralExchangeJwtClient.Options);
10
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ReferralExchangeJwtClient = void 0;
27
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
28
- const Client_1 = require("../Client");
29
- const Fetcher_1 = require("../core/fetcher/Fetcher");
30
- const JWT_TTL_SECONDS = 15;
31
- class ReferralExchangeJwtClient extends Client_1.ReferralExchangeClient {
32
- constructor(options) {
33
- const { privateKey, apiKeyName } = options, baseOptions = __rest(options, ["privateKey", "apiKeyName"]);
34
- const signer = new JwtSigner({ privateKey, issuer: apiKeyName });
35
- const fetcher = createJwtFetcher(signer);
36
- super(Object.assign(Object.assign({}, baseOptions), { fetcher }));
37
- }
38
- }
39
- exports.ReferralExchangeJwtClient = ReferralExchangeJwtClient;
40
- class JwtSigner {
41
- constructor({ privateKey, issuer }) {
42
- this.privateKey = privateKey;
43
- this.issuer = issuer;
44
- }
45
- getToken() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const nowSeconds = Math.floor(Date.now() / 1000);
48
- if (this.cachedToken != null && nowSeconds < this.cachedToken.expiresAtEpochSeconds - 1) {
49
- return this.cachedToken.token;
50
- }
51
- const { token, expiresAtEpochSeconds } = createSignedJwt({
52
- privateKey: this.privateKey,
53
- issuer: this.issuer,
54
- });
55
- this.cachedToken = { token, expiresAtEpochSeconds };
56
- return token;
57
- });
58
- }
59
- }
60
- function createJwtFetcher(signer) {
61
- return (args) => __awaiter(this, void 0, void 0, function* () {
62
- var _a;
63
- const token = yield signer.getToken();
64
- const headers = Object.assign({}, ((_a = args.headers) !== null && _a !== void 0 ? _a : {}));
65
- headers.Authorization = `Bearer ${token}`;
66
- return (0, Fetcher_1.fetcherImpl)(Object.assign(Object.assign({}, args), { headers }));
67
- });
68
- }
69
- function createSignedJwt({ privateKey, issuer }) {
70
- const issuedAt = Math.floor(Date.now() / 1000);
71
- const expiresAtEpochSeconds = issuedAt + JWT_TTL_SECONDS;
72
- const token = jsonwebtoken_1.default.sign({}, privateKey, {
73
- algorithm: "ES256",
74
- issuer,
75
- expiresIn: JWT_TTL_SECONDS,
76
- });
77
- return {
78
- token,
79
- expiresAtEpochSeconds,
80
- };
81
- }