@autentikar/step 2.0.0-alpha.9 → 2.1.0-alpha.3

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/context.d.ts CHANGED
@@ -1,16 +1,11 @@
1
+ import { S as StorageItem, a as Step } from './index-UFlgchNF.js';
2
+ import 'file-type/core';
3
+ import 'zod';
4
+
1
5
  interface Storage {
2
6
  save(name: string, content: Buffer, instance: string): Promise<StorageItem>;
3
7
  get(key: string): Promise<StorageItem | undefined>;
4
8
  }
5
- type PersistentType = "FILESYSTEM" | "MONGODB" | "S3" | "NFS" | "S3-MRAP" | "CDN";
6
- declare class StorageItem {
7
- readonly path: string;
8
- readonly type: PersistentType;
9
- readonly buffer: Buffer;
10
- readonly fileUrl: string;
11
- constructor(path: string, type: PersistentType, buffer: Buffer, fileUrl: string);
12
- getBase64(): string;
13
- }
14
9
 
15
10
  type KVKind = "INSTANCE" | "STEP";
16
11
  interface KV {
@@ -28,8 +23,10 @@ interface Preference {
28
23
 
29
24
  interface System {
30
25
  get<TValue = unknown>(name: string): Promise<TValue | undefined>;
26
+ stage(): string;
31
27
  }
32
28
 
29
+ declare let step: Step;
33
30
  declare let params: Params;
34
31
  /** @deprecated use system. */
35
32
  declare let preference: Preference;
@@ -37,4 +34,4 @@ declare let system: System;
37
34
  declare let kv: KV;
38
35
  declare let asset: Storage;
39
36
 
40
- export { type KV, type Params, type Preference, type Storage, StorageItem, type System, asset, kv, params, preference, system };
37
+ export { type KV, type Params, type Preference, Step, type Storage, type System, asset, kv, params, preference, step, system };
package/dist/context.js CHANGED
@@ -20,29 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/context.ts
21
21
  var context_exports = {};
22
22
  __export(context_exports, {
23
- StorageItem: () => StorageItem,
24
23
  asset: () => asset,
25
24
  kv: () => kv,
26
25
  params: () => params,
27
26
  preference: () => preference,
27
+ step: () => step,
28
28
  system: () => system
29
29
  });
30
30
  module.exports = __toCommonJS(context_exports);
31
-
32
- // src/type/asset.ts
33
- var StorageItem = class {
34
- constructor(path, type, buffer, fileUrl) {
35
- this.path = path;
36
- this.type = type;
37
- this.buffer = buffer;
38
- this.fileUrl = fileUrl;
39
- }
40
- getBase64() {
41
- return this.buffer.toString("base64");
42
- }
43
- };
44
-
45
- // src/context.ts
31
+ var step;
46
32
  var params;
47
33
  var preference;
48
34
  var system;
@@ -50,10 +36,10 @@ var kv;
50
36
  var asset;
51
37
  // Annotate the CommonJS export names for ESM import in node:
52
38
  0 && (module.exports = {
53
- StorageItem,
54
39
  asset,
55
40
  kv,
56
41
  params,
57
42
  preference,
43
+ step,
58
44
  system
59
45
  });
@@ -0,0 +1,212 @@
1
+ import * as file_type_core from 'file-type/core';
2
+ import { z } from 'zod';
3
+
4
+ interface Step {
5
+ params<TValue = unknown>(extend?: unknown): Promise<TValue | undefined>;
6
+ milestone(type: string, status: string, success: boolean): Promise<void>;
7
+ future(type: string, id: string, ttl: number): Promise<void>;
8
+ identity(organization_id: string, instance_id: string, link_session: string | undefined, identity: IdentityDto, data: StepIdentityData): Promise<any>;
9
+ addVendorStat(params: {
10
+ vendor: string;
11
+ service: string;
12
+ amount?: number;
13
+ transaction_id: string;
14
+ meta?: Record<string, unknown>;
15
+ }): Promise<void>;
16
+ }
17
+
18
+ interface AutentikarRequestInit extends RequestInit {
19
+ host: string;
20
+ staging: Staging;
21
+ organization?: {
22
+ id: string;
23
+ alias: string;
24
+ };
25
+ step?: {
26
+ id: string;
27
+ };
28
+ instance?: {
29
+ id: string;
30
+ };
31
+ output?: Record<string, string>;
32
+ link_session: string | undefined;
33
+ params?: unknown;
34
+ }
35
+ declare class AutentikarRequest extends Request {
36
+ readonly organization?: AutentikarRequestInit["organization"];
37
+ readonly step?: AutentikarRequestInit["step"];
38
+ readonly instance?: AutentikarRequestInit["instance"];
39
+ readonly staging?: Staging;
40
+ readonly link_session: string | undefined;
41
+ readonly params?: unknown;
42
+ readonly output?: Record<string, string>;
43
+ readonly host?: string;
44
+ constructor(input: RequestInfo, init?: AutentikarRequestInit);
45
+ }
46
+ interface AutentikarResponseInit extends ResponseInit {
47
+ success: boolean;
48
+ akStatus: string;
49
+ data: {
50
+ output: unknown;
51
+ } & Record<string, unknown>;
52
+ next: string | undefined;
53
+ }
54
+ declare class AutentikarResponse extends Response {
55
+ readonly success: boolean | undefined;
56
+ readonly akStatus: string | undefined;
57
+ readonly data: ({
58
+ output: unknown;
59
+ } & Record<string, unknown>) | undefined;
60
+ readonly next: string | undefined;
61
+ constructor(bodyInit?: BodyInit | null, init?: AutentikarResponseInit);
62
+ static json(data: any, init: AutentikarResponseInit): AutentikarResponse;
63
+ }
64
+
65
+ type StepIdentityData = {
66
+ type: "CARD";
67
+ doc_type: IdentityDto["doc_type"];
68
+ images: {
69
+ face: string;
70
+ front: string;
71
+ back?: string;
72
+ };
73
+ } | {
74
+ type: "FACE";
75
+ provider: "FACETEC" | "IDENTY";
76
+ audit_low: string;
77
+ audit: string;
78
+ map: string;
79
+ } | {
80
+ type: "EMAIL";
81
+ email: string;
82
+ } | {
83
+ type: "CELLPHONE";
84
+ cellphone: string;
85
+ country?: string;
86
+ };
87
+ declare class StepRequest implements Step {
88
+ private step;
89
+ constructor(params: Step);
90
+ addVendorStat(params: {
91
+ vendor: string;
92
+ service: string;
93
+ amount?: number;
94
+ transaction_id: string;
95
+ meta?: Record<string, unknown>;
96
+ }): Promise<void>;
97
+ future(type: string, id: string, ttl: number): Promise<void>;
98
+ milestone(type: string, status: string, success: boolean): Promise<void>;
99
+ params<TValue = unknown>(extend?: unknown): Promise<TValue | undefined>;
100
+ identity(organization_id: string, instance_id: string, link_session: string | undefined, identity: IdentityDto, data: StepIdentityData): Promise<any>;
101
+ }
102
+ declare const AppEnvironmentsSchema: z.ZodObject<{
103
+ STAGING: z.ZodEnum<["LOCAL", "QA", "PROD"]>;
104
+ STEP_TYPE: z.ZodString;
105
+ }, "strip", z.ZodTypeAny, {
106
+ STAGING: "LOCAL" | "QA" | "PROD";
107
+ STEP_TYPE: string;
108
+ }, {
109
+ STAGING: "LOCAL" | "QA" | "PROD";
110
+ STEP_TYPE: string;
111
+ }>;
112
+ declare const IdentitySchemaDto: z.ZodObject<{
113
+ country: z.ZodString;
114
+ doc_type: z.ZodString;
115
+ id_num: z.ZodString;
116
+ }, "strip", z.ZodTypeAny, {
117
+ country: string;
118
+ doc_type: string;
119
+ id_num: string;
120
+ }, {
121
+ country: string;
122
+ doc_type: string;
123
+ id_num: string;
124
+ }>;
125
+ type IdentityDto = z.infer<typeof IdentitySchemaDto>;
126
+ type AppEnvironments = z.infer<typeof AppEnvironmentsSchema>;
127
+ type Staging = AppEnvironments["STAGING"];
128
+ type MethodContextOrganization = {
129
+ id: string;
130
+ };
131
+ type MethodContextFlow = {
132
+ id: string;
133
+ webhook: string | undefined;
134
+ };
135
+ type MethodContextInstance = {
136
+ id: string;
137
+ };
138
+ type MethodContextStep = {
139
+ params: unknown;
140
+ };
141
+ type PersistentType = "FILESYSTEM" | "MONGODB" | "S3" | "NFS" | "S3-MRAP" | "CDN";
142
+ declare class StorageItem {
143
+ readonly path: string;
144
+ readonly type: PersistentType;
145
+ readonly buffer: Buffer;
146
+ readonly fileUrl: string;
147
+ readonly contentType: string | undefined;
148
+ constructor(path: string, type: PersistentType, buffer: Buffer, fileUrl: string, contentType: string | undefined);
149
+ getBase64(): string;
150
+ getContenType(): Promise<file_type_core.MimeType | "unknown">;
151
+ }
152
+ type Method = (req: AutentikarRequest) => Promise<AutentikarResponse>;
153
+ type Resource = (req: AutentikarRequest) => Promise<AutentikarResponse>;
154
+ type AppEnvVariables = {
155
+ instance: {
156
+ id: string;
157
+ session: string | undefined;
158
+ };
159
+ };
160
+ type AppEnv = {
161
+ Bindings: AppEnvironments;
162
+ Variables: AppEnvVariables;
163
+ };
164
+ declare class StepDefinition {
165
+ readonly id: string;
166
+ readonly type: string;
167
+ readonly prev_step: string;
168
+ readonly user_interaction: boolean;
169
+ readonly return_result: boolean;
170
+ readonly end_after_processing: undefined | {
171
+ dispatch: "NO";
172
+ } | {
173
+ dispatch: "AUTO";
174
+ };
175
+ readonly params: Record<string, string> | undefined;
176
+ readonly output: Record<string, string> | undefined;
177
+ readonly milestone: undefined | {
178
+ cloud_hidden?: boolean;
179
+ call_webhook?: boolean;
180
+ };
181
+ constructor(id: string, type: string, prev_step: string, user_interaction: boolean, return_result: boolean, end_after_processing: undefined | {
182
+ dispatch: "NO";
183
+ } | {
184
+ dispatch: "AUTO";
185
+ }, params: Record<string, string> | undefined, output: Record<string, string> | undefined, milestone: undefined | {
186
+ cloud_hidden?: boolean;
187
+ call_webhook?: boolean;
188
+ });
189
+ }
190
+ declare class StepInstance {
191
+ readonly id: string;
192
+ readonly expires_at: number | undefined;
193
+ constructor(id: string, expires_at: number | undefined);
194
+ isExpired(): boolean | 0 | undefined;
195
+ }
196
+ declare class FlowContext {
197
+ readonly id: string;
198
+ readonly webhook: string | undefined;
199
+ constructor(id: string, webhook: string | undefined);
200
+ }
201
+ declare class StepContext {
202
+ readonly org: string;
203
+ readonly flow: FlowContext;
204
+ readonly step: StepDefinition;
205
+ readonly instance: StepInstance;
206
+ readonly expires_at: number | undefined;
207
+ readonly params: unknown;
208
+ constructor(org: string, flow: FlowContext, step: StepDefinition, instance: StepInstance, expires_at: number | undefined, params: unknown);
209
+ isExpired(): boolean | 0 | undefined;
210
+ }
211
+
212
+ export { AutentikarRequest as A, FlowContext as F, IdentitySchemaDto as I, type MethodContextOrganization as M, type PersistentType as P, type Resource as R, StorageItem as S, type Step as a, AutentikarResponse as b, type StepIdentityData as c, StepRequest as d, type IdentityDto as e, type AppEnvironments as f, type Staging as g, type MethodContextFlow as h, type MethodContextInstance as i, type MethodContextStep as j, type Method as k, type AppEnvVariables as l, type AppEnv as m, StepDefinition as n, StepInstance as o, StepContext as p };
@@ -0,0 +1,3 @@
1
+ import 'file-type/core';
2
+ import 'zod';
3
+ export { m as AppEnv, l as AppEnvVariables, f as AppEnvironments, A as AutentikarRequest, b as AutentikarResponse, F as FlowContext, e as IdentityDto, I as IdentitySchemaDto, k as Method, h as MethodContextFlow, i as MethodContextInstance, M as MethodContextOrganization, j as MethodContextStep, P as PersistentType, R as Resource, g as Staging, p as StepContext, n as StepDefinition, c as StepIdentityData, o as StepInstance, d as StepRequest, S as StorageItem } from './index-UFlgchNF.js';
package/dist/index.js ADDED
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ AutentikarRequest: () => AutentikarRequest,
34
+ AutentikarResponse: () => AutentikarResponse,
35
+ FlowContext: () => FlowContext,
36
+ IdentitySchemaDto: () => IdentitySchemaDto,
37
+ StepContext: () => StepContext,
38
+ StepDefinition: () => StepDefinition,
39
+ StepInstance: () => StepInstance,
40
+ StepRequest: () => StepRequest,
41
+ StorageItem: () => StorageItem
42
+ });
43
+ module.exports = __toCommonJS(src_exports);
44
+ var import_zod = require("zod");
45
+ var import_file_type = __toESM(require("file-type"));
46
+
47
+ // src/autentikar-fetch.ts
48
+ var AutentikarRequest = class extends Request {
49
+ organization;
50
+ step;
51
+ instance;
52
+ staging;
53
+ link_session;
54
+ params;
55
+ output;
56
+ host;
57
+ constructor(input, init) {
58
+ super(input, init);
59
+ this.organization = init?.organization;
60
+ this.step = init?.step;
61
+ this.instance = init?.instance;
62
+ this.staging = init?.staging;
63
+ this.link_session = init?.link_session;
64
+ this.params = init?.params;
65
+ this.output = init?.output;
66
+ this.host = init?.host;
67
+ }
68
+ };
69
+ var AutentikarResponse = class _AutentikarResponse extends Response {
70
+ success;
71
+ akStatus;
72
+ data;
73
+ next;
74
+ constructor(bodyInit, init) {
75
+ super(bodyInit, init);
76
+ this.success = init?.success;
77
+ this.akStatus = init?.akStatus;
78
+ this.data = init?.data;
79
+ this.next = init?.next;
80
+ }
81
+ static json(data, init) {
82
+ const body = JSON.stringify(data);
83
+ const headers = new Headers(init.headers || {});
84
+ headers.set("Content-Type", "application/json");
85
+ return new _AutentikarResponse(body, {
86
+ ...init,
87
+ headers
88
+ });
89
+ }
90
+ };
91
+
92
+ // src/index.ts
93
+ var StepRequest = class {
94
+ step;
95
+ constructor(params) {
96
+ this.step = params;
97
+ }
98
+ addVendorStat(params) {
99
+ return this.step.addVendorStat(params);
100
+ }
101
+ future(type, id, ttl) {
102
+ return this.step.future(type, id, ttl);
103
+ }
104
+ milestone(type, status, success) {
105
+ return this.step.milestone(type, status, success);
106
+ }
107
+ params(extend) {
108
+ return this.step.params(extend);
109
+ }
110
+ identity(organization_id, instance_id, link_session, identity, data) {
111
+ return this.step.identity(
112
+ organization_id,
113
+ instance_id,
114
+ link_session,
115
+ identity,
116
+ data
117
+ );
118
+ }
119
+ };
120
+ var AppEnvironmentsSchema = import_zod.z.object({
121
+ STAGING: import_zod.z.enum(["LOCAL", "QA", "PROD"]),
122
+ STEP_TYPE: import_zod.z.string()
123
+ });
124
+ var IdentitySchemaDto = import_zod.z.object({
125
+ country: import_zod.z.string(),
126
+ doc_type: import_zod.z.string(),
127
+ id_num: import_zod.z.string()
128
+ });
129
+ async function getContentTypeFromBuffer(buffer) {
130
+ const type = await import_file_type.default.fromBuffer(buffer);
131
+ if (type) {
132
+ return type.mime;
133
+ } else {
134
+ return "unknown";
135
+ }
136
+ }
137
+ var StorageItem = class {
138
+ constructor(path, type, buffer, fileUrl, contentType) {
139
+ this.path = path;
140
+ this.type = type;
141
+ this.buffer = buffer;
142
+ this.fileUrl = fileUrl;
143
+ this.contentType = contentType;
144
+ }
145
+ getBase64() {
146
+ return this.buffer.toString("base64");
147
+ }
148
+ getContenType() {
149
+ return getContentTypeFromBuffer(this.buffer);
150
+ }
151
+ };
152
+ var StepDefinition = class {
153
+ constructor(id, type, prev_step, user_interaction, return_result, end_after_processing, params, output, milestone) {
154
+ this.id = id;
155
+ this.type = type;
156
+ this.prev_step = prev_step;
157
+ this.user_interaction = user_interaction;
158
+ this.return_result = return_result;
159
+ this.end_after_processing = end_after_processing;
160
+ this.params = params;
161
+ this.output = output;
162
+ this.milestone = milestone;
163
+ }
164
+ };
165
+ var StepInstance = class {
166
+ constructor(id, expires_at) {
167
+ this.id = id;
168
+ this.expires_at = expires_at;
169
+ }
170
+ // public isInvalid() {
171
+ // return this.expires_at && this.expires_at < Date.now();
172
+ // }
173
+ isExpired() {
174
+ return this.expires_at && this.expires_at < Date.now();
175
+ }
176
+ };
177
+ var FlowContext = class {
178
+ constructor(id, webhook) {
179
+ this.id = id;
180
+ this.webhook = webhook;
181
+ }
182
+ };
183
+ var StepContext = class {
184
+ constructor(org, flow, step, instance, expires_at, params) {
185
+ this.org = org;
186
+ this.flow = flow;
187
+ this.step = step;
188
+ this.instance = instance;
189
+ this.expires_at = expires_at;
190
+ this.params = params;
191
+ }
192
+ isExpired() {
193
+ return this.expires_at && this.expires_at < Date.now();
194
+ }
195
+ };
196
+ // Annotate the CommonJS export names for ESM import in node:
197
+ 0 && (module.exports = {
198
+ AutentikarRequest,
199
+ AutentikarResponse,
200
+ FlowContext,
201
+ IdentitySchemaDto,
202
+ StepContext,
203
+ StepDefinition,
204
+ StepInstance,
205
+ StepRequest,
206
+ StorageItem
207
+ });
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@autentikar/step",
3
- "version": "2.0.0-alpha.9",
3
+ "version": "2.1.0-alpha.3",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
8
8
  "exports": {
9
+ ".": "./dist/index.js",
9
10
  "./context": "./dist/context.js",
10
11
  "./package.json": "./package.json"
11
12
  },
12
13
  "typesVersions": {
13
14
  "*": {
15
+ ".": [
16
+ "./dist/index.d.ts"
17
+ ],
14
18
  "context": [
15
19
  "./dist/context.d.ts"
16
20
  ]
@@ -28,5 +32,9 @@
28
32
  "@types/node": "^20.11.5",
29
33
  "tsup": "^8.0.1",
30
34
  "typescript": "^5.2.2"
35
+ },
36
+ "dependencies": {
37
+ "file-type": "16.5.3",
38
+ "zod": "^3.22.4"
31
39
  }
32
40
  }