@vasanthcambium/marketplace-auth 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.
Files changed (78) hide show
  1. package/README.md +84 -0
  2. package/dist/browser/client.d.ts +3 -0
  3. package/dist/browser/client.d.ts.map +1 -0
  4. package/dist/browser/client.js +74 -0
  5. package/dist/browser/client.js.map +1 -0
  6. package/dist/browser/index.d.ts +12 -0
  7. package/dist/browser/index.d.ts.map +1 -0
  8. package/dist/browser/index.js +10 -0
  9. package/dist/browser/index.js.map +1 -0
  10. package/dist/browser/types.d.ts +19 -0
  11. package/dist/browser/types.d.ts.map +1 -0
  12. package/dist/browser/types.js +2 -0
  13. package/dist/browser/types.js.map +1 -0
  14. package/dist/index.d.ts +16 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +2 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/react/AppProvider.d.ts +9 -0
  19. package/dist/react/AppProvider.d.ts.map +1 -0
  20. package/dist/react/AppProvider.js +36 -0
  21. package/dist/react/AppProvider.js.map +1 -0
  22. package/dist/react/index.d.ts +13 -0
  23. package/dist/react/index.d.ts.map +1 -0
  24. package/dist/react/index.js +12 -0
  25. package/dist/react/index.js.map +1 -0
  26. package/dist/react/useAccount.d.ts +9 -0
  27. package/dist/react/useAccount.d.ts.map +1 -0
  28. package/dist/react/useAccount.js +16 -0
  29. package/dist/react/useAccount.js.map +1 -0
  30. package/dist/react/useNBI.d.ts +10 -0
  31. package/dist/react/useNBI.d.ts.map +1 -0
  32. package/dist/react/useNBI.js +15 -0
  33. package/dist/react/useNBI.js.map +1 -0
  34. package/dist/react/useNBIMutation.d.ts +15 -0
  35. package/dist/react/useNBIMutation.d.ts.map +1 -0
  36. package/dist/react/useNBIMutation.js +31 -0
  37. package/dist/react/useNBIMutation.js.map +1 -0
  38. package/dist/react/useSession.d.ts +8 -0
  39. package/dist/react/useSession.d.ts.map +1 -0
  40. package/dist/react/useSession.js +22 -0
  41. package/dist/react/useSession.js.map +1 -0
  42. package/dist/server/createApp.d.ts +3 -0
  43. package/dist/server/createApp.d.ts.map +1 -0
  44. package/dist/server/createApp.js +201 -0
  45. package/dist/server/createApp.js.map +1 -0
  46. package/dist/server/express.d.ts +11 -0
  47. package/dist/server/express.d.ts.map +1 -0
  48. package/dist/server/express.js +86 -0
  49. package/dist/server/express.js.map +1 -0
  50. package/dist/server/hono.d.ts +4 -0
  51. package/dist/server/hono.d.ts.map +1 -0
  52. package/dist/server/hono.js +66 -0
  53. package/dist/server/hono.js.map +1 -0
  54. package/dist/server/index.d.ts +21 -0
  55. package/dist/server/index.d.ts.map +1 -0
  56. package/dist/server/index.js +19 -0
  57. package/dist/server/index.js.map +1 -0
  58. package/dist/server/session.d.ts +15 -0
  59. package/dist/server/session.d.ts.map +1 -0
  60. package/dist/server/session.js +20 -0
  61. package/dist/server/session.js.map +1 -0
  62. package/dist/server/types.d.ts +60 -0
  63. package/dist/server/types.d.ts.map +1 -0
  64. package/dist/server/types.js +2 -0
  65. package/dist/server/types.js.map +1 -0
  66. package/dist/shared/errors.d.ts +33 -0
  67. package/dist/shared/errors.d.ts.map +1 -0
  68. package/dist/shared/errors.js +59 -0
  69. package/dist/shared/errors.js.map +1 -0
  70. package/dist/shared/regions.d.ts +3 -0
  71. package/dist/shared/regions.d.ts.map +1 -0
  72. package/dist/shared/regions.js +13 -0
  73. package/dist/shared/regions.js.map +1 -0
  74. package/dist/shared/types.d.ts +41 -0
  75. package/dist/shared/types.d.ts.map +1 -0
  76. package/dist/shared/types.js +7 -0
  77. package/dist/shared/types.js.map +1 -0
  78. package/package.json +58 -0
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Error classes shared across server, browser, and React subpaths.
3
+ * Branded so consumers can `instanceof`-check across module boundaries.
4
+ */
5
+ export class AuthError extends Error {
6
+ code;
7
+ cause;
8
+ constructor(message, code, cause) {
9
+ super(message);
10
+ this.code = code;
11
+ this.cause = cause;
12
+ this.name = new.target.name;
13
+ }
14
+ }
15
+ // Server-side errors
16
+ export class NonceVerificationError extends AuthError {
17
+ constructor(cause) {
18
+ super('Launch nonce failed verification', 'nonce_verification_failed', cause);
19
+ }
20
+ }
21
+ export class TokenExchangeError extends AuthError {
22
+ status;
23
+ constructor(status, body) {
24
+ super(`Auth Service token exchange failed (${status})`, 'token_exchange_failed', body);
25
+ this.status = status;
26
+ }
27
+ }
28
+ export class SessionNotFoundError extends AuthError {
29
+ constructor() {
30
+ super('Session not found', 'session_not_found');
31
+ }
32
+ }
33
+ export class UpstreamError extends AuthError {
34
+ status;
35
+ constructor(status, message) {
36
+ super(message, 'upstream_error');
37
+ this.status = status;
38
+ }
39
+ }
40
+ // Browser-side errors
41
+ export class BridgeHttpError extends Error {
42
+ status;
43
+ statusText;
44
+ body;
45
+ constructor(status, statusText, body) {
46
+ super(`HTTP ${status} ${statusText}`);
47
+ this.status = status;
48
+ this.statusText = statusText;
49
+ this.body = body;
50
+ this.name = 'BridgeHttpError';
51
+ }
52
+ }
53
+ export class SessionExpiredError extends Error {
54
+ constructor() {
55
+ super('Session expired. The user must re-launch from cnMaestro.');
56
+ this.name = 'SessionExpiredError';
57
+ }
58
+ }
59
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/shared/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,OAAO,SAAU,SAAQ,KAAK;IACW;IAA8B;IAA3E,YAAY,OAAe,EAAkB,IAAY,EAAkB,KAAe;QACxF,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,GAAJ,IAAI,CAAQ;QAAkB,UAAK,GAAL,KAAK,CAAU;QAExF,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,qBAAqB;AAErB,MAAM,OAAO,sBAAuB,SAAQ,SAAS;IACnD,YAAY,KAAe;QACzB,KAAK,CAAC,kCAAkC,EAAE,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAChF,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IACnB;IAA5B,YAA4B,MAAc,EAAE,IAAa;QACvD,KAAK,CAAC,uCAAuC,MAAM,GAAG,EAAE,uBAAuB,EAAE,IAAI,CAAC,CAAC;QAD7D,WAAM,GAAN,MAAM,CAAQ;IAE1C,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IACjD;QACE,KAAK,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;IAClD,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,SAAS;IACd;IAA5B,YAA4B,MAAc,EAAE,OAAe;QACzD,KAAK,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;QADP,WAAM,GAAN,MAAM,CAAQ;IAE1C,CAAC;CACF;AAED,sBAAsB;AAEtB,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAEtB;IACA;IACA;IAHlB,YACkB,MAAc,EACd,UAAkB,EAClB,IAAa;QAE7B,KAAK,CAAC,QAAQ,MAAM,IAAI,UAAU,EAAE,CAAC,CAAC;QAJtB,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAS;QAG7B,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C;QACE,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import type { Region } from './types.js';
2
+ export declare function regionToNbiUrl(region: Region): string;
3
+ //# sourceMappingURL=regions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../../src/shared/regions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AASzC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIrD"}
@@ -0,0 +1,13 @@
1
+ const REGION_TO_NBI = {
2
+ 'us-e1': 'https://us-e1.cloud.cambiumnetworks.com',
3
+ 'eu-w1': 'https://eu-w1.cloud.cambiumnetworks.com',
4
+ 'ap-s1': 'https://ap-s1.cloud.cambiumnetworks.com',
5
+ 'ap-n1': 'https://ap-n1.cloud.cambiumnetworks.com',
6
+ };
7
+ export function regionToNbiUrl(region) {
8
+ const url = REGION_TO_NBI[region];
9
+ if (!url)
10
+ throw new Error(`Unknown region: ${region}`);
11
+ return url;
12
+ }
13
+ //# sourceMappingURL=regions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.js","sourceRoot":"","sources":["../../src/shared/regions.ts"],"names":[],"mappings":"AAEA,MAAM,aAAa,GAA2B;IAC5C,OAAO,EAAE,yCAAyC;IAClD,OAAO,EAAE,yCAAyC;IAClD,OAAO,EAAE,yCAAyC;IAClD,OAAO,EAAE,yCAAyC;CACnD,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;IACvD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Types shared between server, browser, and React subpaths.
3
+ *
4
+ * Keep this file environment-neutral — no Node-only or DOM-only imports.
5
+ */
6
+ export type Region = 'us-e1' | 'eu-w1' | 'ap-s1' | 'ap-n1';
7
+ export type Permission = 'read-only' | 'read-write' | 'full-access';
8
+ export type UserRole = 'super-admin' | 'admin' | 'operator' | 'monitor';
9
+ export interface ApiRoute {
10
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
11
+ path: string;
12
+ description: string;
13
+ }
14
+ export interface Session {
15
+ /** Server stores this internally; browser only knows it via the cn_session cookie. */
16
+ id: string;
17
+ appId: string;
18
+ /** Present on the server side only; never serialized to the browser. */
19
+ jwt?: string;
20
+ /** Present on the server side only; never serialized to the browser. */
21
+ accessToken?: string;
22
+ /** Epoch ms. */
23
+ expiresAt: number;
24
+ accountCid: string;
25
+ userRole: UserRole;
26
+ permission: Permission;
27
+ scopes: {
28
+ tenant: {
29
+ account_cid: string;
30
+ mcids: string[];
31
+ };
32
+ network: {
33
+ network_ids?: string[];
34
+ site_ids?: string[];
35
+ device_ids?: string[];
36
+ };
37
+ };
38
+ /** Resolved at credential-mint time from the Manifest's api_routes_url. */
39
+ apiRoutes: ApiRoute[];
40
+ }
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3D,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,YAAY,GAAG,aAAa,CAAC;AAEpE,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;AAExE,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,sFAAsF;IACtF,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE;QACN,MAAM,EAAE;YAAE,WAAW,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC;QACjD,OAAO,EAAE;YAAE,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC;KACjF,CAAC;IACF,2EAA2E;IAC3E,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types shared between server, browser, and React subpaths.
3
+ *
4
+ * Keep this file environment-neutral — no Node-only or DOM-only imports.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@vasanthcambium/marketplace-auth",
3
+ "version": "0.1.0",
4
+ "description": "Frontend auth + NBI client for MarketApps Platform apps. Browser fetch wrapper and React hooks.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/vasanthcambium/marketapps-developer-platform.git",
9
+ "directory": "sdk/packages/marketplace-auth"
10
+ },
11
+ "bugs": "https://github.com/vasanthcambium/marketapps-developer-platform/issues",
12
+ "keywords": ["cnmaestro", "cambium", "marketapps", "auth", "react", "nbi"],
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
18
+ "./browser": { "types": "./dist/browser/index.d.ts", "import": "./dist/browser/index.js" },
19
+ "./react": { "types": "./dist/react/index.d.ts", "import": "./dist/react/index.js" }
20
+ },
21
+ "files": ["dist", "README.md", "LICENSE"],
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org",
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.build.json",
28
+ "test": "vitest run",
29
+ "typecheck": "tsc --noEmit"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^18.0.0 || ^19.0.0",
33
+ "react-dom": "^18.0.0 || ^19.0.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "react": { "optional": true },
37
+ "react-dom": { "optional": true }
38
+ },
39
+ "dependencies": {
40
+ "jose": "^5.9.0",
41
+ "undici": "^6.19.0",
42
+ "cookie": "^1.0.0",
43
+ "swr": "^2.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.0.0",
47
+ "@types/express": "^4.17.0",
48
+ "@types/cookie": "^1.0.0",
49
+ "@types/react": "^18.0.0",
50
+ "express": "^4.19.0",
51
+ "hono": "^4.0.0",
52
+ "react": "^18.0.0",
53
+ "typescript": "~6.0.0",
54
+ "vitest": "^4.0.0"
55
+ },
56
+ "engines": { "node": ">=22.0" },
57
+ "sideEffects": false
58
+ }